fixes #9149 [backport]
This commit is contained in:
parent
a58f5b6023
commit
07a0a61875
2 changed files with 28 additions and 4 deletions
|
|
@ -4307,15 +4307,17 @@ proc `==`*(x, y: cstring): bool {.magic: "EqCString", noSideEffect,
|
||||||
when defined(nimNoNilSeqs2):
|
when defined(nimNoNilSeqs2):
|
||||||
when not compileOption("nilseqs"):
|
when not compileOption("nilseqs"):
|
||||||
when defined(nimHasUserErrors):
|
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".} =
|
error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} =
|
||||||
discard
|
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".} =
|
error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} =
|
||||||
discard
|
discard
|
||||||
else:
|
else:
|
||||||
proc `==`*(x: string; y: type(nil)): bool {.error.} = discard
|
proc `==`*(x: string; y: type(nil) | type(nil)): bool {.error.} = discard
|
||||||
proc `==`*(x: type(nil); y: string): bool {.error.} = discard
|
proc `==`*(x: type(nil) | 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
|
||||||
|
|
|
||||||
22
tests/overload/tconverter_to_string.nim
Normal file
22
tests/overload/tconverter_to_string.nim
Normal 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"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue