mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-21 14:55:24 +00:00
@@ -1171,7 +1171,9 @@ proc newType*(kind: TTypeKind, owner: PSym): PType =
|
||||
result.lockLevel = UnspecifiedLockLevel
|
||||
when debugIds:
|
||||
registerId(result)
|
||||
#if result.id < 2000:
|
||||
#if result.id == 92231:
|
||||
# echo "KNID ", kind
|
||||
# writeStackTrace()
|
||||
# messageOut(typeKindToStr[kind] & ' has id: ' & toString(result.id))
|
||||
|
||||
proc mergeLoc(a: var TLoc, b: TLoc) =
|
||||
|
||||
@@ -247,6 +247,7 @@ proc makeAndType*(c: PContext, t1, t2: PType): PType =
|
||||
propagateToOwner(result, t1)
|
||||
propagateToOwner(result, t2)
|
||||
result.flags.incl((t1.flags + t2.flags) * {tfHasStatic})
|
||||
result.flags.incl tfHasMeta
|
||||
|
||||
proc makeOrType*(c: PContext, t1, t2: PType): PType =
|
||||
result = newTypeS(tyOr, c)
|
||||
@@ -254,12 +255,14 @@ proc makeOrType*(c: PContext, t1, t2: PType): PType =
|
||||
propagateToOwner(result, t1)
|
||||
propagateToOwner(result, t2)
|
||||
result.flags.incl((t1.flags + t2.flags) * {tfHasStatic})
|
||||
result.flags.incl tfHasMeta
|
||||
|
||||
proc makeNotType*(c: PContext, t1: PType): PType =
|
||||
result = newTypeS(tyNot, c)
|
||||
result.sons = @[t1]
|
||||
propagateToOwner(result, t1)
|
||||
result.flags.incl(t1.flags * {tfHasStatic})
|
||||
result.flags.incl tfHasMeta
|
||||
|
||||
proc nMinusOne*(n: PNode): PNode =
|
||||
result = newNode(nkCall, n.info, @[
|
||||
|
||||
@@ -389,7 +389,7 @@ proc isOpImpl(c: PContext, n: PNode): PNode =
|
||||
maybeLiftType(t2, c, n.info)
|
||||
var m: TCandidate
|
||||
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.typ = n.typ
|
||||
|
||||
@@ -834,7 +834,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||
cp.kind = tyUserTypeClassInst
|
||||
return addImplicitGeneric(cp)
|
||||
|
||||
for i in 1 .. (paramType.sons.len - 2):
|
||||
for i in 1 .. paramType.len-2:
|
||||
var lifted = liftingWalk(paramType.sons[i])
|
||||
if lifted != nil:
|
||||
paramType.sons[i] = lifted
|
||||
@@ -847,7 +847,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||
result.shouldHaveMeta
|
||||
|
||||
of tyGenericInvocation:
|
||||
for i in 1 .. <paramType.sonsLen:
|
||||
for i in 1 .. <paramType.len:
|
||||
let lifted = liftingWalk(paramType.sons[i])
|
||||
if lifted != nil: paramType.sons[i] = lifted
|
||||
when false:
|
||||
|
||||
@@ -233,7 +233,9 @@ proc instCopyType*(cl: var TReplTypeVars, t: PType): PType =
|
||||
# XXX: relying on allowMetaTypes is a kludge
|
||||
result = copyType(t, t.owner, cl.allowMetaTypes)
|
||||
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 =
|
||||
# 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)
|
||||
result = isNone
|
||||
|
||||
of tyNone:
|
||||
if a.kind == tyNone: result = isEqual
|
||||
else:
|
||||
internalAssert false
|
||||
internalError " unknown type kind " & $f.kind
|
||||
|
||||
proc cmpTypes*(c: PContext, f, a: PType): TTypeRelation =
|
||||
var m: TCandidate
|
||||
|
||||
@@ -16,7 +16,8 @@ struct SystemManager {
|
||||
""".}
|
||||
|
||||
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]()
|
||||
|
||||
@@ -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
|
||||
import macros
|
||||
|
||||
@@ -20,7 +20,7 @@ static: assert iii is TestFN
|
||||
|
||||
proc foo11 : testTypesym(void) =
|
||||
echo "HI!"
|
||||
static: assert foo11 is proc():void
|
||||
static: assert foo11 is (proc():void {.nimcall.})
|
||||
|
||||
var sss: testTypesym(seq[int])
|
||||
static: assert sss is seq[int]
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
discard """
|
||||
output: '''true true false yes'''
|
||||
output: '''true true false yes
|
||||
false
|
||||
false
|
||||
false
|
||||
true
|
||||
true
|
||||
no'''
|
||||
"""
|
||||
|
||||
proc IsVoid[T](): string =
|
||||
@@ -28,7 +34,7 @@ no s.items is iterator: float
|
||||
yes s.items is iterator: TNumber
|
||||
no s.items is iterator: object
|
||||
|
||||
type
|
||||
type
|
||||
Iter[T] = iterator: T
|
||||
|
||||
yes s.items is Iter[TNumber]
|
||||
@@ -51,3 +57,34 @@ yes Foo[4, int] is Bar[int]
|
||||
no Foo[4, int] 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)
|
||||
|
||||
Reference in New Issue
Block a user