allows implicitRangeConvs for literals (#25542)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
ringabout
2026-02-26 02:10:00 +08:00
committed by GitHub
parent 74499e4561
commit a3157537e1
3 changed files with 15 additions and 11 deletions

View File

@@ -1550,6 +1550,7 @@ proc track(tracked: PEffects, n: PNode) =
# Check for implicit range conversions
if n.kind == nkHiddenStdConv and (not tracked.isArrayIndexing) and
n[1].kind notin {nkCharLit..nkUInt64Lit, nkFloatLit..nkFloat128Lit} and
shouldWarnRangeConversion(tracked.config, n.info, n.typ, n[1].typ):
message(tracked.config, n.info, warnImplicitRangeConversion,
typeToString(n[1].typ) & " -> " & typeToString(n.typ))

View File

@@ -1,11 +0,0 @@
discard """
matrix: "--warning:systemRangeConversion --warningaserror:systemRangeConversion"
action: "reject"
errormsg: "implicit range conversion int literal(12) -> Natural"
"""
proc foo(x: Natural) =
discard
foo(12)

View File

@@ -0,0 +1,14 @@
discard """
matrix: "--warning:systemRangeConversion --warningaserror:systemRangeConversion"
"""
proc foo(x: range[0..100]) = discard
foo(12)
type
Float = range[0.0..100.0]
proc bar(x: Float) = discard
bar(12.0)