mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 08:54:53 +00:00
fixes #9149 [backport]
This commit is contained in:
@@ -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
|
||||
|
||||
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"
|
||||
Reference in New Issue
Block a user