summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semobjconstr.nim7
-rw-r--r--tests/constructors/t5965_1.nim10
-rw-r--r--tests/constructors/t5965_2.nim10
3 files changed, 26 insertions, 1 deletions
diff --git a/compiler/semobjconstr.nim b/compiler/semobjconstr.nim
index f4c225526..b331d05a1 100644
--- a/compiler/semobjconstr.nim
+++ b/compiler/semobjconstr.nim
@@ -44,7 +44,9 @@ proc locateFieldInInitExpr(field: PSym, initExpr: PNode): PNode =
   let fieldId = field.name.id
   for i in 1 .. <initExpr.len:
     let assignment = initExpr[i]
-    internalAssert assignment.kind == nkExprColonExpr
+    if assignment.kind != nkExprColonExpr:
+      localError(initExpr.info, "incorrect object construction syntax")
+      continue
 
     if fieldId == considerQuotedIdent(assignment[0]).id:
       return assignment
@@ -278,6 +280,9 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
   for i in 1.. <result.len:
     let field = result[i]
     if nfSem notin field.flags:
+      if field.kind != nkExprColonExpr:
+        localError(n.info, "incorrect object construction syntax")
+        continue
       let id = considerQuotedIdent(field[0])
       # This node was not processed. There are two possible reasons:
       # 1) It was shadowed by a field with the same name on the left
diff --git a/tests/constructors/t5965_1.nim b/tests/constructors/t5965_1.nim
new file mode 100644
index 000000000..9f947f859
--- /dev/null
+++ b/tests/constructors/t5965_1.nim
@@ -0,0 +1,10 @@
+discard """
+  file: "t5965_1.nim"
+  line: 10
+  errormsg: "incorrect object construction syntax"
+"""
+
+type Foo = object
+  a, b, c: int
+
+discard Foo(a: 1, 2)
diff --git a/tests/constructors/t5965_2.nim b/tests/constructors/t5965_2.nim
new file mode 100644
index 000000000..a3f7174c9
--- /dev/null
+++ b/tests/constructors/t5965_2.nim
@@ -0,0 +1,10 @@
+discard """
+  file: "t5965_2.nim"
+  line: 10
+  errormsg: "incorrect object construction syntax"
+"""
+
+type Foo = object
+  a: int
+
+discard Foo(a: 1, 2)