Skip to content

Using sum types with module specifiers typechecks inconsistently #18095

Open
@tersec

Description

@tersec

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.

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