-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
template return type is ignored in type check when template called inside a generic, and it accepts invalid code.
Example 1
template bar(t): string = high(t)
proc fun[A](key: A) =
var h = 1 and bar(@[1])
fun(0)
# if calling `var h = 1 and bar(@[1])` directly (not inside a generic), we get a correct error msgCurrent Output 1
compiles
Expected Output 1
Error: type mismatch: got <int> but expected 'string'
Example 2
template bar(t): string = high(t)
proc fun[A](key: A) =
var h = 1'u and bar(@[1])
fun(0)Current Output 2
Error: type mismatch: got <uint, int>
but expected one of:
proc `and`(x, y: uint): uint
first type mismatch at position: 2
required type for y: uint
but expression 'high(@[1])' is of type: int
proc `and`(x, y: uint64): uint64
first type mismatch at position: 2
required type for y: uint64
but expression 'high(@[1])' is of type: int
10 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them
expression: 1'u and high(@[1])
var h = 1'u and bar(@[1])
Expected Output 2
Error: type mismatch: got <int> but expected 'string'
Additional Information
- recent devel 1.1.1 1e30310
- related but different from template parameter type checking broken #11794