mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
@@ -833,10 +833,20 @@ proc genAddSubInt(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode) =
|
||||
c.genNarrow(n, dest)
|
||||
|
||||
proc genConv(c: PCtx; n, arg: PNode; dest: var TDest; opc=opcConv) =
|
||||
if n.typ.kind == arg.typ.kind and arg.typ.kind == tyProc:
|
||||
# don't do anything for lambda lifting conversions:
|
||||
let t2 = n.typ.skipTypes({tyDistinct})
|
||||
let targ2 = arg.typ.skipTypes({tyDistinct})
|
||||
|
||||
proc implicitConv(): bool =
|
||||
if sameType(t2, targ2): return true
|
||||
# xxx consider whether to use t2 and targ2 here
|
||||
if n.typ.kind == arg.typ.kind and arg.typ.kind == tyProc:
|
||||
# don't do anything for lambda lifting conversions:
|
||||
return true
|
||||
|
||||
if implicitConv():
|
||||
gen(c, arg, dest)
|
||||
return
|
||||
|
||||
let tmp = c.genx(arg)
|
||||
if dest < 0: dest = c.getTemp(n.typ)
|
||||
c.gABC(n, opc, dest, tmp)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
discard """
|
||||
targets: "c js"
|
||||
output: '''
|
||||
tdistinct
|
||||
25
|
||||
@@ -138,3 +139,34 @@ block tRequiresInit:
|
||||
accept:
|
||||
let s = "test"
|
||||
doAssert s == "test"
|
||||
|
||||
type Foo = distinct string
|
||||
|
||||
template main() =
|
||||
# xxx put everything here to test under RT + VM
|
||||
block: # bug #12282
|
||||
block:
|
||||
proc test() =
|
||||
var s: Foo
|
||||
s.string.add('c')
|
||||
doAssert s.string == "c" # was failing
|
||||
test()
|
||||
|
||||
block:
|
||||
proc add(a: var Foo, b: char) {.borrow.}
|
||||
proc test() =
|
||||
var s: Foo
|
||||
s.add('c')
|
||||
doAssert s.string == "c" # was ok
|
||||
test()
|
||||
|
||||
block:
|
||||
proc add(a: var Foo, b: char) {.borrow.}
|
||||
proc test() =
|
||||
var s: string
|
||||
s.Foo.add('c')
|
||||
doAssert s.string == "c" # was failing
|
||||
test()
|
||||
|
||||
static: main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user