fixes #21887; Type conversion on overloaded enum field does not always call (#21908)

* fixes #21887; Type conversion on overloaded enum field does not always call

* remove comments

* add a test case

* restrict it to enums
This commit is contained in:
ringabout
2023-05-26 15:24:43 +08:00
committed by GitHub
parent 908e971732
commit ab4d044a81
2 changed files with 11 additions and 0 deletions

View File

@@ -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

View File

@@ -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