Nim icon indicating copy to clipboard operation
Nim copied to clipboard

Problem with forward declaration

Open zeitbit opened this issue 3 years ago • 2 comments

Hello,

This works OK:

proc fn(): int32 | int64 =
    1

var v = fn()

But using a forward declaration fails, "Error: invalid type: 'int32 or int64' for var":

proc fn(): int32 | int64

var v = fn()

proc fn(): int32 | int64 =
    1

Specifying the type (int32 or int) produces this error: "Error: type mismatch: got 'int32 or int64' for 'fn()' but expected 'int32'"

proc fn(): int32 | int64

var a: int32 = fn()

proc fn(): int32 | int64 =
    1

And with int64 the exception: "Error: unhandled exception: ccgtypes.nim(198, 17) false mapType: tyOr [AssertionDefect]"

proc fn(): int32 | int64

var a: int64 = fn()

proc fn(): int32 | int64 =
    1

Nim Compiler Version 1.5.1 [Windows: amd64] Compiled at 2021-04-03

zeitbit avatar Apr 07 '21 18:04 zeitbit