summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semexprs.nim3
-rw-r--r--tests/ccgbugs/tmissingderef2.nim25
2 files changed, 27 insertions, 1 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 8aaf4f9d8..723045fb0 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -1274,7 +1274,8 @@ proc propertyWriteAccess(c: PContext, n, nOrig, a: PNode): PNode =
   # this is ugly. XXX Semantic checking should use the ``nfSem`` flag for
   # nodes?
   let aOrig = nOrig[0]
-  result = newNode(nkCall, n.info, sons = @[setterId, a[0], semExpr(c, n[1])])
+  result = newNode(nkCall, n.info, sons = @[setterId, a[0],
+                                            semExprWithType(c, n[1])])
   result.flags.incl nfDotSetter
   let orig = newNode(nkCall, n.info, sons = @[setterId, aOrig[0], nOrig[1]])
   result = semOverloadedCallAnalyseEffects(c, result, orig, {})
diff --git a/tests/ccgbugs/tmissingderef2.nim b/tests/ccgbugs/tmissingderef2.nim
new file mode 100644
index 000000000..59cd24dd1
--- /dev/null
+++ b/tests/ccgbugs/tmissingderef2.nim
@@ -0,0 +1,25 @@
+discard """
+  output: "c"
+"""
+
+# bug #5079
+
+import tables, strutils
+
+type Test = ref object
+  s: string
+
+proc `test=`(t: Test, s: string) =
+  t.s = s
+
+var t = Test()
+
+#t.test = spaces(2) # -- works
+
+var a = newTable[string, string]()
+a["b"] = "c"
+
+#t.s = a["b"] # -- works
+#t.test a["b"] # -- works
+t.test = a["b"] # -- prints "out of memory" and quits
+echo t.s