Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/sempass2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1552,9 +1552,10 @@ proc track(tracked: PEffects, n: PNode) =
message(tracked.config, n.info, warnPtrToCstringConv,
$n[1].typ)

# Check for implicit range conversions
# Check for implicit range conversions. Compile-time constants are already
# fully known here, so only non-constant values need the downsizing warning.
if n.kind == nkHiddenStdConv and (not tracked.isArrayIndexing) and
n[1].kind notin {nkCharLit..nkUInt64Lit, nkFloatLit..nkFloat128Lit} and
getConstExpr(tracked.ownerModule, n[1], tracked.c.idgen, tracked.graph) == nil and
shouldWarnRangeConversion(tracked.config, n.info, n.typ, n[1].typ):
Comment thread
ringabout marked this conversation as resolved.
Outdated
message(tracked.config, n.info, warnImplicitRangeConversion,
typeToString(n[1].typ) & " -> " & typeToString(n.typ))
Expand Down
29 changes: 28 additions & 1 deletion tests/range/timplicitrangedownsizing.nim
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,31 @@ wf = smallFloatRange # OK - SmallFloat range fits in WideFloatRange
proc foo(x: Natural) =
discard

foo(12)
foo(12)

block:
type
E = enum
ea, eb

R = range[eb..eb]
I = range[0..3]

proc accept(r: R) = discard
proc accept(i: I) = discard

var r: R
var i: I
const enumOk = eb
const enumAlias = enumOk
const intOk = 1 + 2

r = eb
r = enumOk
r = enumAlias
accept(eb)
accept(enumOk)
accept(enumAlias)

i = intOk
accept(intOk)
Comment thread
ringabout marked this conversation as resolved.
Loading