Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
timotheecour opened this issue Feb 18, 2020 · 1 comment · Fixed by #23642
Closed

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

timotheecour opened this issue Feb 18, 2020 · 1 comment · Fixed by #23642

Comments

@timotheecour
Copy link
Member

timotheecour commented Feb 18, 2020

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

@metagn
Copy link
Collaborator

metagn commented Dec 26, 2023

Correct output since 1.6.18 (not 1.6.16)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants