Nim
Nim copied to clipboard
proc types don't match as part of proc param typeclasses
trafficstars
proc types don't match as part of proc param typeclasses
Example
type A = proc()
proc f(j: A) = discard
proc g(j: A | int) = discard
proc h(j: A | A) = discard
proc a() = discard
# Work
f() do (): discard
f(a)
g(0)
# Fail to compile
g(a)
h() do (): discard
h(a)
Current Output
proc_type_params_in_typeclass.nim(15, 2) Error: type mismatch: got <proc (){.noSideEffect, gcsafe, locks: 0.}>
but expected one of:
proc g(j: A | int)
first type mismatch at position: 1
required type for j: A or int
but expression 'a' is of type: proc (){.noSideEffect, gcsafe, locks: 0.}
expression: g(a)
If g(a) is commented out:
proc_type_params_in_typeclass.nim(16, 2) Error: type mismatch: got <proc (){.noSideEffect, gcsafe, locks: 0.}>
but expected one of:
proc h(j: A | A)
first type mismatch at position: 1
required type for j: A or A
but expression 'proc () = (discard )' is of type: proc (){.noSideEffect, gcsafe, locks: 0.}
expression: h(proc () = (discard ))
If g(a) and h() do (): discard are commented out:
proc_type_params_in_typeclass.nim(17, 2) Error: type mismatch: got <proc (){.noSideEffect, gcsafe, locks: 0.}>
but expected one of:
proc h(j: A | A)
first type mismatch at position: 1
required type for j: A or A
but expression 'a' is of type: proc (){.noSideEffect, gcsafe, locks: 0.}
expression: h(a)
Checked, with essentially same results (1.5.1 shown), with:
Nim Compiler Version 1.2.12 [Linux: amd64]
Compiled at 2021-06-22
Copyright (c) 2006-2020 by Andreas Rumpf
git hash: 121628357ec7fae91335bd392f03b0e6dd249319
active boot switches: -d:release
Nim Compiler Version 1.4.2 [Linux: amd64]
Compiled at 2021-05-13
Copyright (c) 2006-2020 by Andreas Rumpf
active boot switches: -d:release
and git master head:
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-06-22
Copyright (c) 2006-2021 by Andreas Rumpf
git hash: d8488e41e85c84a6b5fe687940b7fee10314d1f1
active boot switches: -d:release
Expected Output
Successful compilation.