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

Compiler throwing error, losing track of alias names in recursions #13702

Open
wolfgang371 opened this issue Jul 24, 2023 · 1 comment
Open
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:generics

Comments

@wolfgang371
Copy link

That's probably a compiler error that results in a silly error message:

method Base(Cell)#b must return (Base(Cell) | Nil) but it is returning Cell

where Cell actually has exactly this definition.

# double recursion
class Base(T)
    def a : T
        b # calls the method that returns T|Nil
    end
    def b : T|Nil # Error: method Base(Cell)#b must return (Base(Cell) | Nil) but it is returning Cell
        a
    end
end

alias Cell = Base(Cell)|Nil # recursion needed, Nil needed

Base(Cell).new.a # needs to call the method which returns T

I'm running

Crystal 1.9.2 [1908c816f] (2023-07-19)
LLVM: 15.0.7
Default target: x86_64-unknown-linux-gnu

on Ubuntu 18.04

@wolfgang371 wolfgang371 added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label Jul 24, 2023
@yxhuvud
Copy link
Contributor

yxhuvud commented Jul 24, 2023

I'd say this is a duplicate of #5155 . At the very least it is extremely related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:generics
Projects
None yet
Development

No branches or pull requests

3 participants