Skip to content

Commit

Permalink
fixes #20227; skip distinct types for genObjConstr [JS backend] (#20229)
Browse files Browse the repository at this point in the history
fixes #20227; skip distinct types for genObjConstr
  • Loading branch information
ringabout authored Aug 24, 2022
1 parent b8dc58d commit e832fea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2272,6 +2272,7 @@ proc genObjConstr(p: PProc, n: PNode, r: var TCompRes) =
r.kind = resExpr
var initList : Rope
var fieldIDs = initIntSet()
let nTyp = n.typ.skipTypes(abstractInst)
for i in 1..<n.len:
if i > 1: initList.add(", ")
var it = n[i]
Expand All @@ -2280,7 +2281,7 @@ proc genObjConstr(p: PProc, n: PNode, r: var TCompRes) =
gen(p, val, a)
var f = it[0].sym
if f.loc.r == nil: f.loc.r = mangleName(p.module, f)
fieldIDs.incl(lookupFieldAgain(n.typ, f).id)
fieldIDs.incl(lookupFieldAgain(nTyp, f).id)

let typ = val.typ.skipTypes(abstractInst)
if a.typ == etyBaseIndex:
Expand Down
17 changes: 17 additions & 0 deletions tests/stdlib/tmisc_issues.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
discard """
targets: "c cpp js"
"""

# bug #20227
type
Data = object
id: int

Test = distinct Data

Object = object
data: Test


var x: Object = Object(data: Test(Data(id: 12)))
doAssert Data(x.data).id == 12

0 comments on commit e832fea

Please sign in to comment.