nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.54k stars 1.47k forks source link

`nim check` doesn't report enum conversion error #20192

Open RSDuck opened 2 years ago

RSDuck commented 2 years ago

What happened?

Originally described in https://github.com/pragmagic/vscode-nim/issues/198


type
  All = enum
    a1
    a2
    b1
    b2
  A = range[a1..a2]
  B = range[b1..b2]

proc test(a: A) =
  echo a

test(b1)

As far as I can tell it correctly fails with the error "Error: conversion from All to A is invalid" when compiling with nim c, while running nim check on the file results in no error at all.

Nim Version

Nim Compiler Version 1.7.1 [Windows: amd64] Compiled at 2022-07-29 Copyright (c) 2006-2022 by Andreas Rumpf

git hash: 528b6d1c3f001944a7a7754c8884178e365e6871 active boot switches: -d:release

Current Standard Output Logs

Hint: used config file 'C:\Nim\config\nim.cfg' [Conf]
Hint: used config file 'C:\Nim\config\config.nims' [Conf]
..................................................................
C:\...\test123.nim(10, 3) Hint: 'B' is declared but not used [XDeclaredButNotUsed]
Hint: 
28939 lines; 0.377s; 25.602MiB peakmem; proj: C:\...\test123.nim; out: unknownOutput [SuccessX]

Expected Standard Output Logs

$ nim c ./test123.nim
Hint: used config file 'C:\Nim\config\nim.cfg' [Conf]
Hint: used config file 'C:\Nim\config\config.nims' [Conf]
..................................................................
C:\...\test123.nim(15, 6) Error: conversion from All to A is invalid

Possible Solution

No response

Additional Information

No response

metagn commented 2 years ago

The error normally seems to be given during constant folding. Which is weird, is nim check not supposed to do constant folding?

ringabout commented 2 years ago

It seems that the conversion checking is executed by codegen pass, not sempass.