diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index ae118159cf..44a73cf10c 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -349,6 +349,9 @@ proc semConv(c: PContext, n: PNode; expectedType: PType = nil): PNode = targetType.skipTypes(abstractPtrs).kind == tyObject: localError(c.config, n.info, "object construction uses ':', not '='") var op = semExprWithType(c, n[1]) + if op.kind == nkClosedSymChoice and op.len > 0 and + op[0].sym.kind == skEnumField: # resolves overloadedable enums + op = ambiguousSymChoice(c, n, op) if targetType.kind != tyGenericParam and targetType.isMetaType: let final = inferWithMetatype(c, targetType, op, true) result.add final diff --git a/tests/enum/toverloadable_enums.nim b/tests/enum/toverloadable_enums.nim index 9bb5514674..5fdcb18238 100644 --- a/tests/enum/toverloadable_enums.nim +++ b/tests/enum/toverloadable_enums.nim @@ -118,3 +118,11 @@ block: # test with macros/templates doAssert isOneMS(e2) doAssert isOneT(e1) doAssert isOneT(e2) + +block: # bug #21908 + type + EnumA = enum A = 300, B + EnumB = enum A = 10 + EnumC = enum C + + doAssert typeof(EnumC(A)) is EnumC