fixes #9149 [backport]

This commit is contained in:
Araq
2019-01-29 14:31:43 +01:00
parent a58f5b6023
commit 07a0a61875
2 changed files with 28 additions and 4 deletions

View File

@@ -4307,15 +4307,17 @@ proc `==`*(x, y: cstring): bool {.magic: "EqCString", noSideEffect,
when defined(nimNoNilSeqs2):
when not compileOption("nilseqs"):
when defined(nimHasUserErrors):
proc `==`*(x: string; y: type(nil)): bool {.
# bug #9149; ensure that 'type(nil)' does not match *too* well by using 'type(nil) | type(nil)'.
# Eventually (in 0.20?) we will be able to remove this hack completely.
proc `==`*(x: string; y: type(nil) | type(nil)): bool {.
error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} =
discard
proc `==`*(x: type(nil); y: string): bool {.
proc `==`*(x: type(nil) | type(nil); y: string): bool {.
error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} =
discard
else:
proc `==`*(x: string; y: type(nil)): bool {.error.} = discard
proc `==`*(x: type(nil); y: string): bool {.error.} = discard
proc `==`*(x: string; y: type(nil) | type(nil)): bool {.error.} = discard
proc `==`*(x: type(nil) | type(nil); y: string): bool {.error.} = discard
template closureScope*(body: untyped): untyped =
## Useful when creating a closure in a loop to capture local loop variables by

View File

@@ -0,0 +1,22 @@
discard """
output: '''123
c is not nil'''
"""
# bug #9149
type
Container = ref object
data: int
converter containerToString*(x: Container): string = $x.data
var c = Container(data: 123)
var str = string c
echo str
if c == nil: # this line can compile on v0.18, but not on 0.19
echo "c is nil"
if not c.isNil:
echo "c is not nil"