closed ambiguous enum defaults to first overload (#20457)

* closed ambiguous enum defaults to first overload

* add warning

* turn to hint

* work around config
This commit is contained in:
metagn
2022-10-01 14:30:23 +03:00
committed by GitHub
parent 24b81e9df6
commit cfff454cf9
8 changed files with 37 additions and 8 deletions

View File

@@ -87,6 +87,14 @@ proc semExprWithType(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType
result = semExprCheck(c, n, flags, expectedType)
if result.typ == nil and efInTypeof in flags:
result.typ = c.voidType
elif (result.typ == nil or result.typ.kind == tyNone) and
result.kind == nkClosedSymChoice and
result[0].sym.kind == skEnumField:
# if overloaded enum field could not choose a type from a closed list,
# choose the first resolved enum field, i.e. the latest in scope
# to mirror old behavior
msgSymChoiceUseQualifier(c, result, hintAmbiguousEnum)
result = result[0]
elif result.typ == nil or result.typ == c.enforceVoidContext:
localError(c.config, n.info, errExprXHasNoType %
renderTree(result, {renderNoComments}))