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
commit cfff454cf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 37 additions and 8 deletions

View file

@ -591,7 +591,9 @@ proc semCaseBranch(c: PContext, t, branch: PNode, branchIndex: int,
branch[i] = semCaseBranchRange(c, t, b, covered)
else:
# constant sets and arrays are allowed:
var r = semConstExpr(c, b)
# set expected type to selector type for type inference
# even if it can be a different type like a set or array
var r = semConstExpr(c, b, expectedType = t[0].typ)
if r.kind in {nkCurly, nkBracket} and r.len == 0 and branch.len == 2:
# discarding ``{}`` and ``[]`` branches silently
delSon(branch, 0)