Skip to content

template return type ignored in type check, accepts invalid code #13426

@timotheecour

Description

@timotheecour

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 msg

Current 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions