fix #866; generic static params

This commit is contained in:
Zahary Karadjov 2014-03-09 23:38:17 +02:00
commit 45a345e93d
5 changed files with 35 additions and 20 deletions

View file

@ -818,6 +818,9 @@ type
counter*: int counter*: int
data*: TObjectSeq data*: TObjectSeq
TImplication* = enum
impUnknown, impNo, impYes
# BUGFIX: a module is overloadable so that a proc can have the # BUGFIX: a module is overloadable so that a proc can have the
# same name as an imported module. This is necessary because of # same name as an imported module. This is necessary because of
# the poor naming choices in the standard library. # the poor naming choices in the standard library.
@ -865,6 +868,7 @@ const
nkCallKinds* = {nkCall, nkInfix, nkPrefix, nkPostfix, nkCallKinds* = {nkCall, nkInfix, nkPrefix, nkPostfix,
nkCommand, nkCallStrLit, nkHiddenCallConv} nkCommand, nkCallStrLit, nkHiddenCallConv}
nkLiterals* = {nkCharLit..nkTripleStrLit}
nkLambdaKinds* = {nkLambda, nkDo} nkLambdaKinds* = {nkLambda, nkDo}
declarativeDefs* = {nkProcDef, nkMethodDef, nkIteratorDef, nkConverterDef} declarativeDefs* = {nkProcDef, nkMethodDef, nkIteratorDef, nkConverterDef}
procDefs* = nkLambdaKinds + declarativeDefs procDefs* = nkLambdaKinds + declarativeDefs

View file

@ -157,6 +157,12 @@ proc leValue*(a, b: PNode): bool =
#InternalError(a.info, "leValue") #InternalError(a.info, "leValue")
discard discard
proc weakLeValue*(a, b: PNode): TImplication =
if a.kind notin nkLiterals or b.kind notin nkLiterals:
result = impUnknown
else:
result = if leValue(a, b): impYes else: impNo
proc lookupInRecord(n: PNode, field: PIdent): PSym = proc lookupInRecord(n: PNode, field: PIdent): PSym =
result = nil result = nil
case n.kind case n.kind

View file

@ -274,10 +274,6 @@ proc pred(n: PNode): PNode =
else: else:
result = n result = n
type
TImplication* = enum
impUnknown, impNo, impYes
proc impliesEq(fact, eq: PNode): TImplication = proc impliesEq(fact, eq: PNode): TImplication =
let (loc, val) = if isLocation(eq.sons[1]): (1, 2) else: (2, 1) let (loc, val) = if isLocation(eq.sons[1]): (1, 2) else: (2, 1)

View file

@ -154,19 +154,28 @@ proc semRangeAux(c: PContext, n: PNode, prev: PType): PType =
result.n = newNodeI(nkRange, n.info) result.n = newNodeI(nkRange, n.info)
if (n[1].kind == nkEmpty) or (n[2].kind == nkEmpty): if (n[1].kind == nkEmpty) or (n[2].kind == nkEmpty):
localError(n.info, errRangeIsEmpty) localError(n.info, errRangeIsEmpty)
var a = semConstExpr(c, n[1])
var b = semConstExpr(c, n[2]) var imm: array[2, PNode]
if not sameType(a.typ, b.typ): imm[0] = semExprWithType(c, n[1], {efDetermineType})
imm[1] = semExprWithType(c, n[2], {efDetermineType})
if not sameType(imm[0].typ, imm[1].typ):
localError(n.info, errPureTypeMismatch) localError(n.info, errPureTypeMismatch)
elif a.typ.kind notin {tyInt..tyInt64,tyEnum,tyBool,tyChar, elif not imm[0].typ.isOrdinalType:
tyFloat..tyFloat128,tyUInt8..tyUInt32}:
localError(n.info, errOrdinalTypeExpected) localError(n.info, errOrdinalTypeExpected)
elif enumHasHoles(a.typ): elif enumHasHoles(imm[0].typ):
localError(n.info, errEnumXHasHoles, a.typ.sym.name.s) localError(n.info, errEnumXHasHoles, imm[0].typ.sym.name.s)
elif not leValue(a, b): localError(n.info, errRangeIsEmpty)
addSon(result.n, a) for i in 0..1:
addSon(result.n, b) if hasGenericArguments(imm[i]):
addSonSkipIntLit(result, b.typ) result.n.addSon makeStaticExpr(c, imm[i])
else:
result.n.addSon semConstExpr(c, imm[i])
if weakLeValue(result.n[0], result.n[1]) == impNo:
localError(n.info, errRangeIsEmpty)
addSonSkipIntLit(result, imm[0].typ)
proc semRange(c: PContext, n: PNode, prev: PType): PType = proc semRange(c: PContext, n: PNode, prev: PType): PType =
result = nil result = nil

View file

@ -4062,8 +4062,8 @@ Static params can also appear in the signatures of generic types:
AffineTransform2D[T] = Matrix[3, 3, T] AffineTransform2D[T] = Matrix[3, 3, T]
AffineTransform3D[T] = Matrix[4, 4, T] AffineTransform3D[T] = Matrix[4, 4, T]
AffineTransform3D[float] # OK var m1: AffineTransform3D[float] # OK
AffineTransform2D[string] # Error, `string` is not a `Number` var m2: AffineTransform2D[string] # Error, `string` is not a `Number`
typedesc typedesc