fixes #1444
This commit is contained in:
parent
c9563d28a8
commit
09ab1703e1
6 changed files with 30 additions and 13 deletions
|
|
@ -36,10 +36,11 @@ proc semGenericStmtScope(c: PContext, n: PNode,
|
||||||
template macroToExpand(s: expr): expr =
|
template macroToExpand(s: expr): expr =
|
||||||
s.kind in {skMacro, skTemplate} and (s.typ.len == 1 or sfImmediate in s.flags)
|
s.kind in {skMacro, skTemplate} and (s.typ.len == 1 or sfImmediate in s.flags)
|
||||||
|
|
||||||
proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym): PNode =
|
proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym,
|
||||||
|
ctx: var IntSet): PNode =
|
||||||
incl(s.flags, sfUsed)
|
incl(s.flags, sfUsed)
|
||||||
case s.kind
|
case s.kind
|
||||||
of skUnknown:
|
of skUnknown:
|
||||||
# Introduced in this pass! Leave it as an identifier.
|
# Introduced in this pass! Leave it as an identifier.
|
||||||
result = n
|
result = n
|
||||||
of skProc, skMethod, skIterators, skConverter:
|
of skProc, skMethod, skIterators, skConverter:
|
||||||
|
|
@ -48,11 +49,13 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym): PNode =
|
||||||
if macroToExpand(s):
|
if macroToExpand(s):
|
||||||
let n = fixImmediateParams(n)
|
let n = fixImmediateParams(n)
|
||||||
result = semTemplateExpr(c, n, s, {efNoSemCheck})
|
result = semTemplateExpr(c, n, s, {efNoSemCheck})
|
||||||
|
result = semGenericStmt(c, result, {}, ctx)
|
||||||
else:
|
else:
|
||||||
result = symChoice(c, n, s, scOpen)
|
result = symChoice(c, n, s, scOpen)
|
||||||
of skMacro:
|
of skMacro:
|
||||||
if macroToExpand(s):
|
if macroToExpand(s):
|
||||||
result = semMacroExpr(c, n, n, s, {efNoSemCheck})
|
result = semMacroExpr(c, n, n, s, {efNoSemCheck})
|
||||||
|
result = semGenericStmt(c, result, {}, ctx)
|
||||||
else:
|
else:
|
||||||
result = symChoice(c, n, s, scOpen)
|
result = symChoice(c, n, s, scOpen)
|
||||||
of skGenericParam:
|
of skGenericParam:
|
||||||
|
|
@ -80,7 +83,7 @@ proc lookup(c: PContext, n: PNode, flags: TSemGenericFlags,
|
||||||
elif s.name.id in ctx:
|
elif s.name.id in ctx:
|
||||||
result = symChoice(c, n, s, scForceOpen)
|
result = symChoice(c, n, s, scForceOpen)
|
||||||
else:
|
else:
|
||||||
result = semGenericStmtSymbol(c, n, s)
|
result = semGenericStmtSymbol(c, n, s, ctx)
|
||||||
# else: leave as nkIdent
|
# else: leave as nkIdent
|
||||||
|
|
||||||
proc newDot(n, b: PNode): PNode =
|
proc newDot(n, b: PNode): PNode =
|
||||||
|
|
@ -95,8 +98,9 @@ proc fuzzyLookup(c: PContext, n: PNode, flags: TSemGenericFlags,
|
||||||
|
|
||||||
var s = qualifiedLookUp(c, n, luf)
|
var s = qualifiedLookUp(c, n, luf)
|
||||||
if s != nil:
|
if s != nil:
|
||||||
result = semGenericStmtSymbol(c, n, s)
|
result = semGenericStmtSymbol(c, n, s, ctx)
|
||||||
else:
|
else:
|
||||||
|
n.sons[0] = semGenericStmt(c, n.sons[0], flags, ctx)
|
||||||
result = n
|
result = n
|
||||||
let n = n[1]
|
let n = n[1]
|
||||||
let ident = considerQuotedIdent(n)
|
let ident = considerQuotedIdent(n)
|
||||||
|
|
@ -107,7 +111,7 @@ proc fuzzyLookup(c: PContext, n: PNode, flags: TSemGenericFlags,
|
||||||
elif s.name.id in ctx:
|
elif s.name.id in ctx:
|
||||||
result = newDot(result, symChoice(c, n, s, scForceOpen))
|
result = newDot(result, symChoice(c, n, s, scForceOpen))
|
||||||
else:
|
else:
|
||||||
let sym = semGenericStmtSymbol(c, n, s)
|
let sym = semGenericStmtSymbol(c, n, s, ctx)
|
||||||
if sym.kind == nkSym:
|
if sym.kind == nkSym:
|
||||||
result = newDot(result, symChoice(c, n, s, scForceOpen))
|
result = newDot(result, symChoice(c, n, s, scForceOpen))
|
||||||
else:
|
else:
|
||||||
|
|
@ -158,13 +162,15 @@ proc semGenericStmt(c: PContext, n: PNode,
|
||||||
of skMacro:
|
of skMacro:
|
||||||
if macroToExpand(s):
|
if macroToExpand(s):
|
||||||
result = semMacroExpr(c, n, n, s, {efNoSemCheck})
|
result = semMacroExpr(c, n, n, s, {efNoSemCheck})
|
||||||
|
result = semGenericStmt(c, result, {}, ctx)
|
||||||
else:
|
else:
|
||||||
n.sons[0] = symChoice(c, n.sons[0], s, scOption)
|
n.sons[0] = symChoice(c, n.sons[0], s, scOption)
|
||||||
result = n
|
result = n
|
||||||
of skTemplate:
|
of skTemplate:
|
||||||
if macroToExpand(s):
|
if macroToExpand(s):
|
||||||
let n = fixImmediateParams(n)
|
let n = fixImmediateParams(n)
|
||||||
result = semTemplateExpr(c, n, s, {efNoSemCheck})
|
result = semTemplateExpr(c, n, s, {efNoSemCheck})
|
||||||
|
result = semGenericStmt(c, result, {}, ctx)
|
||||||
else:
|
else:
|
||||||
n.sons[0] = symChoice(c, n.sons[0], s, scOption)
|
n.sons[0] = symChoice(c, n.sons[0], s, scOption)
|
||||||
result = n
|
result = n
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ proc mget*[A](s: var HashSet[A], key: A): var A =
|
||||||
## for sharing.
|
## for sharing.
|
||||||
assert s.isValid, "The set needs to be initialized."
|
assert s.isValid, "The set needs to be initialized."
|
||||||
var index = rawGet(s, key)
|
var index = rawGet(s, key)
|
||||||
if index >= 0: result = t.data[index].key
|
if index >= 0: result = s.data[index].key
|
||||||
else: raise newException(KeyError, "key not found: " & $key)
|
else: raise newException(KeyError, "key not found: " & $key)
|
||||||
|
|
||||||
proc contains*[A](s: HashSet[A], key: A): bool =
|
proc contains*[A](s: HashSet[A], key: A): bool =
|
||||||
|
|
|
||||||
|
|
@ -874,13 +874,13 @@ proc contains*[T](s: Slice[T], value: T): bool {.noSideEffect, inline.} =
|
||||||
## assert((1..3).contains(4) == false)
|
## assert((1..3).contains(4) == false)
|
||||||
result = s.a <= value and value <= s.b
|
result = s.a <= value and value <= s.b
|
||||||
|
|
||||||
template `in` * (x, y: expr): expr {.immediate.} = contains(y, x)
|
template `in` * (x, y: expr): expr {.immediate, dirty.} = contains(y, x)
|
||||||
## Sugar for contains
|
## Sugar for contains
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## assert(1 in (1..3) == true)
|
## assert(1 in (1..3) == true)
|
||||||
## assert(5 in (1..3) == false)
|
## assert(5 in (1..3) == false)
|
||||||
template `notin` * (x, y: expr): expr {.immediate.} = not contains(y, x)
|
template `notin` * (x, y: expr): expr {.immediate, dirty.} = not contains(y, x)
|
||||||
## Sugar for not containing
|
## Sugar for not containing
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ proc popFrame {.compilerRtl, inl.} = discard
|
||||||
proc setFrame(s: PFrame) {.compilerRtl, inl.} = discard
|
proc setFrame(s: PFrame) {.compilerRtl, inl.} = discard
|
||||||
proc pushSafePoint(s: PSafePoint) {.compilerRtl, inl.} = discard
|
proc pushSafePoint(s: PSafePoint) {.compilerRtl, inl.} = discard
|
||||||
proc popSafePoint {.compilerRtl, inl.} = discard
|
proc popSafePoint {.compilerRtl, inl.} = discard
|
||||||
proc pushCurrentException(e: ref E_Base) {.compilerRtl, inl.} = discard
|
proc pushCurrentException(e: ref Exception) {.compilerRtl, inl.} = discard
|
||||||
proc popCurrentException {.compilerRtl, inl.} = discard
|
proc popCurrentException {.compilerRtl, inl.} = discard
|
||||||
|
|
||||||
# some platforms have native support for stack traces:
|
# some platforms have native support for stack traces:
|
||||||
|
|
@ -32,7 +32,7 @@ const
|
||||||
proc quitOrDebug() {.inline.} =
|
proc quitOrDebug() {.inline.} =
|
||||||
quit(1)
|
quit(1)
|
||||||
|
|
||||||
proc raiseException(e: ref E_Base, ename: CString) {.compilerRtl.} =
|
proc raiseException(e: ref Exception, ename: cstring) {.compilerRtl.} =
|
||||||
sysFatal(ENoExceptionToReraise, "exception handling is not available")
|
sysFatal(ENoExceptionToReraise, "exception handling is not available")
|
||||||
|
|
||||||
proc reraiseException() {.compilerRtl.} =
|
proc reraiseException() {.compilerRtl.} =
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,11 @@ type MyObj = object
|
||||||
proc foo*(b: any) =
|
proc foo*(b: any) =
|
||||||
var o: MyObj
|
var o: MyObj
|
||||||
echo b.baz, " ", o.x.baz, " ", b.baz()
|
echo b.baz, " ", o.x.baz, " ", b.baz()
|
||||||
|
|
||||||
|
import sets
|
||||||
|
|
||||||
|
var intset = initSet[int]()
|
||||||
|
|
||||||
|
proc func*[T](a: T) =
|
||||||
|
if a in intset: echo("true")
|
||||||
|
else: echo("false")
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''5 5 5'''
|
output: '''5 5 5
|
||||||
|
false'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import mdotlookup
|
import mdotlookup
|
||||||
|
|
||||||
foo(7)
|
foo(7)
|
||||||
|
# bug #1444
|
||||||
|
func(4)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue