parent
daefc2567b
commit
e55f5d1fd4
10 changed files with 58 additions and 11 deletions
|
|
@ -1171,7 +1171,9 @@ proc newType*(kind: TTypeKind, owner: PSym): PType =
|
||||||
result.lockLevel = UnspecifiedLockLevel
|
result.lockLevel = UnspecifiedLockLevel
|
||||||
when debugIds:
|
when debugIds:
|
||||||
registerId(result)
|
registerId(result)
|
||||||
#if result.id < 2000:
|
#if result.id == 92231:
|
||||||
|
# echo "KNID ", kind
|
||||||
|
# writeStackTrace()
|
||||||
# messageOut(typeKindToStr[kind] & ' has id: ' & toString(result.id))
|
# messageOut(typeKindToStr[kind] & ' has id: ' & toString(result.id))
|
||||||
|
|
||||||
proc mergeLoc(a: var TLoc, b: TLoc) =
|
proc mergeLoc(a: var TLoc, b: TLoc) =
|
||||||
|
|
|
||||||
|
|
@ -247,6 +247,7 @@ proc makeAndType*(c: PContext, t1, t2: PType): PType =
|
||||||
propagateToOwner(result, t1)
|
propagateToOwner(result, t1)
|
||||||
propagateToOwner(result, t2)
|
propagateToOwner(result, t2)
|
||||||
result.flags.incl((t1.flags + t2.flags) * {tfHasStatic})
|
result.flags.incl((t1.flags + t2.flags) * {tfHasStatic})
|
||||||
|
result.flags.incl tfHasMeta
|
||||||
|
|
||||||
proc makeOrType*(c: PContext, t1, t2: PType): PType =
|
proc makeOrType*(c: PContext, t1, t2: PType): PType =
|
||||||
result = newTypeS(tyOr, c)
|
result = newTypeS(tyOr, c)
|
||||||
|
|
@ -254,12 +255,14 @@ proc makeOrType*(c: PContext, t1, t2: PType): PType =
|
||||||
propagateToOwner(result, t1)
|
propagateToOwner(result, t1)
|
||||||
propagateToOwner(result, t2)
|
propagateToOwner(result, t2)
|
||||||
result.flags.incl((t1.flags + t2.flags) * {tfHasStatic})
|
result.flags.incl((t1.flags + t2.flags) * {tfHasStatic})
|
||||||
|
result.flags.incl tfHasMeta
|
||||||
|
|
||||||
proc makeNotType*(c: PContext, t1: PType): PType =
|
proc makeNotType*(c: PContext, t1: PType): PType =
|
||||||
result = newTypeS(tyNot, c)
|
result = newTypeS(tyNot, c)
|
||||||
result.sons = @[t1]
|
result.sons = @[t1]
|
||||||
propagateToOwner(result, t1)
|
propagateToOwner(result, t1)
|
||||||
result.flags.incl(t1.flags * {tfHasStatic})
|
result.flags.incl(t1.flags * {tfHasStatic})
|
||||||
|
result.flags.incl tfHasMeta
|
||||||
|
|
||||||
proc nMinusOne*(n: PNode): PNode =
|
proc nMinusOne*(n: PNode): PNode =
|
||||||
result = newNode(nkCall, n.info, @[
|
result = newNode(nkCall, n.info, @[
|
||||||
|
|
|
||||||
|
|
@ -389,7 +389,7 @@ proc isOpImpl(c: PContext, n: PNode): PNode =
|
||||||
maybeLiftType(t2, c, n.info)
|
maybeLiftType(t2, c, n.info)
|
||||||
var m: TCandidate
|
var m: TCandidate
|
||||||
initCandidate(c, m, t2)
|
initCandidate(c, m, t2)
|
||||||
let match = typeRel(m, t2, t1) != isNone
|
let match = typeRel(m, t2, t1) >= isSubtype # isNone
|
||||||
result = newIntNode(nkIntLit, ord(match))
|
result = newIntNode(nkIntLit, ord(match))
|
||||||
|
|
||||||
result.typ = n.typ
|
result.typ = n.typ
|
||||||
|
|
|
||||||
|
|
@ -834,7 +834,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
cp.kind = tyUserTypeClassInst
|
cp.kind = tyUserTypeClassInst
|
||||||
return addImplicitGeneric(cp)
|
return addImplicitGeneric(cp)
|
||||||
|
|
||||||
for i in 1 .. (paramType.sons.len - 2):
|
for i in 1 .. paramType.len-2:
|
||||||
var lifted = liftingWalk(paramType.sons[i])
|
var lifted = liftingWalk(paramType.sons[i])
|
||||||
if lifted != nil:
|
if lifted != nil:
|
||||||
paramType.sons[i] = lifted
|
paramType.sons[i] = lifted
|
||||||
|
|
@ -847,7 +847,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
result.shouldHaveMeta
|
result.shouldHaveMeta
|
||||||
|
|
||||||
of tyGenericInvocation:
|
of tyGenericInvocation:
|
||||||
for i in 1 .. <paramType.sonsLen:
|
for i in 1 .. <paramType.len:
|
||||||
let lifted = liftingWalk(paramType.sons[i])
|
let lifted = liftingWalk(paramType.sons[i])
|
||||||
if lifted != nil: paramType.sons[i] = lifted
|
if lifted != nil: paramType.sons[i] = lifted
|
||||||
when false:
|
when false:
|
||||||
|
|
|
||||||
|
|
@ -233,7 +233,9 @@ proc instCopyType*(cl: var TReplTypeVars, t: PType): PType =
|
||||||
# XXX: relying on allowMetaTypes is a kludge
|
# XXX: relying on allowMetaTypes is a kludge
|
||||||
result = copyType(t, t.owner, cl.allowMetaTypes)
|
result = copyType(t, t.owner, cl.allowMetaTypes)
|
||||||
result.flags.incl tfFromGeneric
|
result.flags.incl tfFromGeneric
|
||||||
result.flags.excl tfInstClearedFlags
|
if not (t.kind in tyMetaTypes or
|
||||||
|
(t.kind == tyStatic and t.n == nil)):
|
||||||
|
result.flags.excl tfInstClearedFlags
|
||||||
|
|
||||||
proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
|
proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
|
||||||
# tyGenericInvocation[A, tyGenericInvocation[A, B]]
|
# tyGenericInvocation[A, tyGenericInvocation[A, B]]
|
||||||
|
|
|
||||||
|
|
@ -1108,8 +1108,10 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
|
||||||
localError(f.n.info, errTypeExpected)
|
localError(f.n.info, errTypeExpected)
|
||||||
result = isNone
|
result = isNone
|
||||||
|
|
||||||
|
of tyNone:
|
||||||
|
if a.kind == tyNone: result = isEqual
|
||||||
else:
|
else:
|
||||||
internalAssert false
|
internalError " unknown type kind " & $f.kind
|
||||||
|
|
||||||
proc cmpTypes*(c: PContext, f, a: PType): TTypeRelation =
|
proc cmpTypes*(c: PContext, f, a: PType): TTypeRelation =
|
||||||
var m: TCandidate
|
var m: TCandidate
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ struct SystemManager {
|
||||||
""".}
|
""".}
|
||||||
|
|
||||||
type Input {.importcpp: "System::Input".} = object
|
type Input {.importcpp: "System::Input".} = object
|
||||||
proc getSubsystem*[T](): ptr T {.importcpp: "SystemManager::getSubsystem<'*0>()".}
|
proc getSubsystem*[T](): ptr T {.
|
||||||
|
importcpp: "SystemManager::getSubsystem<'*0>()", nodecl.}
|
||||||
|
|
||||||
let input: ptr Input = getSubsystem[Input]()
|
let input: ptr Input = getSubsystem[Input]()
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
# tests to see if a symbol returned from macros.getType() can
|
# tests to see if a symbol returned from macros.getType() can
|
||||||
# be used as a type
|
# be used as a type
|
||||||
import macros
|
import macros
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ static: assert iii is TestFN
|
||||||
|
|
||||||
proc foo11 : testTypesym(void) =
|
proc foo11 : testTypesym(void) =
|
||||||
echo "HI!"
|
echo "HI!"
|
||||||
static: assert foo11 is proc():void
|
static: assert foo11 is (proc():void {.nimcall.})
|
||||||
|
|
||||||
var sss: testTypesym(seq[int])
|
var sss: testTypesym(seq[int])
|
||||||
static: assert sss is seq[int]
|
static: assert sss is seq[int]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''true true false yes'''
|
output: '''true true false yes
|
||||||
|
false
|
||||||
|
false
|
||||||
|
false
|
||||||
|
true
|
||||||
|
true
|
||||||
|
no'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc IsVoid[T](): string =
|
proc IsVoid[T](): string =
|
||||||
|
|
@ -28,7 +34,7 @@ no s.items is iterator: float
|
||||||
yes s.items is iterator: TNumber
|
yes s.items is iterator: TNumber
|
||||||
no s.items is iterator: object
|
no s.items is iterator: object
|
||||||
|
|
||||||
type
|
type
|
||||||
Iter[T] = iterator: T
|
Iter[T] = iterator: T
|
||||||
|
|
||||||
yes s.items is Iter[TNumber]
|
yes s.items is Iter[TNumber]
|
||||||
|
|
@ -51,3 +57,34 @@ yes Foo[4, int] is Bar[int]
|
||||||
no Foo[4, int] is Baz[4]
|
no Foo[4, int] is Baz[4]
|
||||||
yes Foo[4, float] is Baz[4]
|
yes Foo[4, float] is Baz[4]
|
||||||
|
|
||||||
|
|
||||||
|
# bug #2505
|
||||||
|
|
||||||
|
echo(8'i8 is int32)
|
||||||
|
|
||||||
|
# bug #1853
|
||||||
|
type SeqOrSet[E] = seq[E] or set[E]
|
||||||
|
type SeqOfInt = seq[int]
|
||||||
|
type SeqOrSetOfInt = SeqOrSet[int]
|
||||||
|
|
||||||
|
# This prints "false", which seems less correct that (1) printing "true" or (2)
|
||||||
|
# raising a compiler error.
|
||||||
|
echo seq is SeqOrSet
|
||||||
|
|
||||||
|
# This prints "false", as expected.
|
||||||
|
echo seq is SeqOrSetOfInt
|
||||||
|
|
||||||
|
# This prints "true", as expected.
|
||||||
|
echo SeqOfInt is SeqOrSet
|
||||||
|
|
||||||
|
# This causes an internal error (filename: compiler/semtypes.nim, line: 685).
|
||||||
|
echo SeqOfInt is SeqOrSetOfInt
|
||||||
|
|
||||||
|
# bug #2522
|
||||||
|
proc test[T](x: T) =
|
||||||
|
when T is typedesc:
|
||||||
|
echo "yes"
|
||||||
|
else:
|
||||||
|
echo "no"
|
||||||
|
|
||||||
|
test(7)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue