mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-28 09:31:38 +00:00
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:
@@ -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}))
|
||||
|
||||
Reference in New Issue
Block a user