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

Calling type aliased type class through untyped template param fails. #18202

Closed
tersec opened this issue Jun 6, 2021 · 1 comment · Fixed by #24525
Closed

Calling type aliased type class through untyped template param fails. #18202

tersec opened this issue Jun 6, 2021 · 1 comment · Fixed by #24525

Comments

@tersec
Copy link
Contributor

tersec commented Jun 6, 2021

Calling type aliased type class through untyped template param fails.

The example shows the complete cartesian product of

  • use joined or split functions for the first param, i.e. handle L separately than B or not, and
  • use the type alias U or R | S in the proc signature for the second param.

Three of these four work, but using joined functions and the type alias U doesn't.

Example

type
  R = object
  S = object
  U = R | S

  L = object
  B = object
  C = B | L

proc f(n: L, q: R | S) = echo "L"
proc f(n: B, q: R | S) = echo "B"

proc g(n: C, q: R | S) = echo (when n is L: "L" else: "B")

proc h(n: L, q: U) = echo "L"
proc h(n: B, q: U) = echo "B"

proc j(n: C, q: U) = echo (when n is L: "L" else: "B")

proc e(n: B | L, a: R) =
  template t(operations: untyped, fn: untyped) = fn(n, operations)

  # Work as expected
  t(a, f)
  t(a, g)
  t(a, j)

  # Error: type mismatch: got <R, proc [*missing parameters*](n: B, q: U) | proc [*missing parameters*](n: L, q: U)>
  t(a, h)

e(L(), R())
e(B(), R())

Current Output

please check whether the problem still exists in git head before posting,
see rebuilding the compiler.

type_aliases_with_template.nim(29, 4) Error: type mismatch: got <R, proc [*missing parameters*](n: B, q: U) | proc [*missing parameters*](n: L, q: U)>
but expected one of: 
template t(operations: untyped; fn: untyped)
  first type mismatch at position: 2
  required type for fn: untyped
  but expression 'h' is of type: None

expression: t(a, h)

Tested to be the same on:

$ ./env.sh nim --version
Nim Compiler Version 1.2.12 [Linux: amd64]
Compiled at 2021-06-02
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 the current git head,

Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-06-06
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: e7816a3e77ab0f821d66667dfc448f1898199f59
active boot switches: -d:release

Expected Output

L
L
L
L
B
B
B
B
@metagn
Copy link
Collaborator

metagn commented Sep 28, 2024

Works in devel, even when changing the signature of t to include typed or have return type untyped. No idea what the root cause was, can't say for certain there isn't another related issue. Doesn't work in 2.0.8. Doesn't seem to need --experimental:openSym.

metagn added a commit to metagn/Nim that referenced this issue Dec 8, 2024
@Araq Araq closed this as completed in aeb3fe9 Dec 9, 2024
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