summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-08-24 19:31:44 +0800
committerGitHub <noreply@github.com>2022-08-24 13:31:44 +0200
commite832fea160409dff94799b3c79e018c6e9a957d6 (patch)
treef6545cd981d40670e4475f2290ff298fc77572ed
parentb8dc58d8843af7dbd0ee2f3274e0d4cf18391dd2 (diff)
downloadNim-e832fea160409dff94799b3c79e018c6e9a957d6.tar.gz
fixes #20227; skip distinct types for genObjConstr [JS backend] (#20229)
fixes #20227; skip distinct types for genObjConstr
-rw-r--r--compiler/jsgen.nim3
-rw-r--r--tests/stdlib/tmisc_issues.nim17
2 files changed, 19 insertions, 1 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index 39009bd2f..bbc64a2f0 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -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]
@@ -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:
diff --git a/tests/stdlib/tmisc_issues.nim b/tests/stdlib/tmisc_issues.nim
new file mode 100644
index 000000000..ed57818b1
--- /dev/null
+++ b/tests/stdlib/tmisc_issues.nim
@@ -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