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

Using sum types with module specifiers typechecks inconsistently #18095

Open
tersec opened this issue May 25, 2021 · 1 comment
Open

Using sum types with module specifiers typechecks inconsistently #18095

tersec opened this issue May 25, 2021 · 1 comment

Comments

@tersec
Copy link
Contributor

tersec commented May 25, 2021

Using sum types with module specifiers typechecks inconsistently.

Example

module z:

type
  A* = object
    discard

  B* = object
    discard

  C* = A | B

module z2 (or any other name, probably):

import z

when true:
  # These work fine.
  discard default(z.A)
  proc f1(x: z.A) = discard
  discard default(z.B)
  proc f2(x: z.B) = discard
  discard default(A)
  proc f3(x: A) = discard
  discard default(B)
  proc f4(x: B) = discard
  proc f5(x: C) = discard
  proc f6(x: z.C | C) = discard

# Doesn't compile.
proc f(x: z.C) = discard

Current Output

z2.nim(17, 7) Error: invalid type: 'typeof(C)' in this context: 'proc (x: typeof(C))' for proc

Tested on 1.2.12, 1.4.2, and current head:

Nim Compiler Version 1.2.12 [Linux: amd64]
Compiled at 2021-05-25
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
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-05-25
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 478f717377c4cd60cfce112b8b21d58031b118b4
active boot switches: -d:release

Expected Output

Successful compilation.

@timotheecour
Copy link
Member

reduced with a single module t12311:

type
  A* = object
  B* = object
  C* = A | B
type B2 = t12311.B
type C2 = t12311.C
proc fn1(a: t12311.B) = discard
proc fn2(a: C) = discard
proc f3(a: C2) = discard # Error: invalid type: 'C2' in this context: 'proc (a: C2)' for proc
# proc fn4(a: t12311.C) = discard # ditto

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

No branches or pull requests

3 participants