changes how the now illegal 'string == nil' comparison is detected

This commit is contained in:
Andreas Rumpf 2018-08-15 16:31:56 +02:00
commit 0da91aa744
5 changed files with 12 additions and 7 deletions

View file

@ -75,3 +75,4 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimIncrSeqV3") defineSymbol("nimIncrSeqV3")
defineSymbol("nimAshr") defineSymbol("nimAshr")
defineSymbol("nimNoNilSeqs") defineSymbol("nimNoNilSeqs")
defineSymbol("nimNoNilSeqs2")

View file

@ -1355,11 +1355,7 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
else: else:
result = isEqual result = isEqual
of tyNil: result = f.allowsNil of tyNil: result = f.allowsNil
of tyString: of tyString: result = isConvertible
if optNilSeqs in c.c.config.options or c.magic != mEqCString:
result = isConvertible
else:
result = isNone
of tyPtr: of tyPtr:
# ptr[Tag, char] is not convertible to 'cstring' for now: # ptr[Tag, char] is not convertible to 'cstring' for now:
if a.len == 1: if a.len == 1:
@ -1819,7 +1815,7 @@ proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType,
# see tests/tgenericconverter: # see tests/tgenericconverter:
let srca = typeRel(m, src, a) let srca = typeRel(m, src, a)
if srca notin {isEqual, isGeneric, isSubtype}: continue if srca notin {isEqual, isGeneric, isSubtype}: continue
let constraint = c.converters[i].typ.n[1].sym.constraint let constraint = c.converters[i].typ.n[1].sym.constraint
if not constraint.isNil and not matchNodeKinds(constraint, arg): if not constraint.isNil and not matchNodeKinds(constraint, arg):
continue continue

View file

@ -1200,7 +1200,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
tyNone, tyForward, tyFromExpr: tyNone, tyForward, tyFromExpr:
result = t result = t
of tyNil: of tyNil:
if kind != skConst: result = t if kind != skConst and kind != skParam: result = t
of tyString, tyBool, tyChar, tyEnum, tyInt..tyUInt64, tyCString, tyPointer: of tyString, tyBool, tyChar, tyEnum, tyInt..tyUInt64, tyCString, tyPointer:
result = nil result = nil
of tyOrdinal: of tyOrdinal:

View file

@ -4048,6 +4048,10 @@ proc `==`*(x, y: cstring): bool {.magic: "EqCString", noSideEffect,
elif x.isNil or y.isNil: result = false elif x.isNil or y.isNil: result = false
else: result = strcmp(x, y) == 0 else: result = strcmp(x, y) == 0
when defined(nimNoNilSeqs2):
proc `==`*(x: string; y: type(nil)): bool {.error.} = discard
proc `==`*(x: type(nil); y: string): bool {.error.} = discard
template closureScope*(body: untyped): untyped = template closureScope*(body: untyped): untyped =
## Useful when creating a closure in a loop to capture local loop variables by ## Useful when creating a closure in a loop to capture local loop variables by
## their current iteration values. Example: ## their current iteration values. Example:

View file

@ -1,2 +1,6 @@
discard """
output: ""
"""
var x = @["1", "", "3"] var x = @["1", "", "3"]
doAssert $x == """@["1", "", "3"]""" doAssert $x == """@["1", "", "3"]"""