summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semexprs.nim7
-rw-r--r--tests/objects/tobjconstr.nim26
2 files changed, 16 insertions, 17 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 3d2ba2568..d236687c3 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -1907,12 +1907,11 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
   var ids = initIntSet()
   for i in 1.. <n.len:
     let it = n.sons[i]
-    if it.kind != nkExprColonExpr or it.sons[0].kind notin {nkSym, nkIdent}:
+    if it.kind != nkExprColonExpr:
       localError(n.info, errNamedExprExpected)
       break
-    var id: PIdent
-    if it.sons[0].kind == nkIdent: id = it.sons[0].ident
-    else: id = it.sons[0].sym.name
+    let id = considerQuotedIdent(it.sons[0])
+
     if containsOrIncl(ids, id.id):
       localError(it.info, errFieldInitTwice, id.s)
     var e = semExprWithType(c, it.sons[1], flags*{efAllowDestructor})
diff --git a/tests/objects/tobjconstr.nim b/tests/objects/tobjconstr.nim
index 3bd785728..226fe98f7 100644
--- a/tests/objects/tobjconstr.nim
+++ b/tests/objects/tobjconstr.nim
@@ -1,14 +1,14 @@
 discard """
-  output: '''(k: kindA, a: (x: abc, z: [1, 1, 3]), empty: ())
-(k: kindA, a: (x: abc, z: [1, 2, 3]), empty: ())
-(k: kindA, a: (x: abc, z: [1, 3, 3]), empty: ())
-(k: kindA, a: (x: abc, z: [1, 4, 3]), empty: ())
-(k: kindA, a: (x: abc, z: [1, 5, 3]), empty: ())
-(k: kindA, a: (x: abc, z: [1, 6, 3]), empty: ())
-(k: kindA, a: (x: abc, z: [1, 7, 3]), empty: ())
-(k: kindA, a: (x: abc, z: [1, 8, 3]), empty: ())
-(k: kindA, a: (x: abc, z: [1, 9, 3]), empty: ())
-(k: kindA, a: (x: abc, z: [1, 10, 3]), empty: ())'''
+  output: '''(k: kindA, a: (x: abc, z: [1, 1, 3]), method: ())
+(k: kindA, a: (x: abc, z: [1, 2, 3]), method: ())
+(k: kindA, a: (x: abc, z: [1, 3, 3]), method: ())
+(k: kindA, a: (x: abc, z: [1, 4, 3]), method: ())
+(k: kindA, a: (x: abc, z: [1, 5, 3]), method: ())
+(k: kindA, a: (x: abc, z: [1, 6, 3]), method: ())
+(k: kindA, a: (x: abc, z: [1, 7, 3]), method: ())
+(k: kindA, a: (x: abc, z: [1, 8, 3]), method: ())
+(k: kindA, a: (x: abc, z: [1, 9, 3]), method: ())
+(k: kindA, a: (x: abc, z: [1, 10, 3]), method: ())'''
 """
 
 type
@@ -20,9 +20,9 @@ type
   TDummy = ref object
     case k: TKind
     of kindXY: x, y: int
-    of kindA: 
+    of kindA:
       a: TArg
-      empty: TEmpty
+      `method`: TEmpty # bug #1791
 
 proc `$`[T](s: seq[T]): string =
   # XXX why is that not in the stdlib?
@@ -34,7 +34,7 @@ proc `$`[T](s: seq[T]): string =
 
 proc main() =
   for i in 1..10:
-    let d = TDummy(k: kindA, a: TArg(x: "abc", z: @[1,i,3]), empty: TEmpty())
+    let d = TDummy(k: kindA, a: TArg(x: "abc", z: @[1,i,3]), `method`: TEmpty())
     echo d[]
 
 main()