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

Detect recursive structs through tuples, named tuples and recursive aliases #5156

Merged
merged 4 commits into from Oct 23, 2017
Merged

Detect recursive structs through tuples, named tuples and recursive aliases #5156

merged 4 commits into from Oct 23, 2017

Conversation

asterite
Copy link
Member

Fixes #4454
Fixes #4455

This compiles right now but shouldn't:

struct Foo
  @x : Tuple(Foo, Foo)

  def initialize(@x)
  end
end

Since a tuple is like a struct, the representation of Foo would expand infinitely. A check was missing regarding tuples and named tuples (first two commits).

Likewise, this compiles but shouldn't:

struct Bar(T)
  def initialize(@x : T)
  end
end

alias Foo = Int32 | Bar(Foo)

The problem is that the representation of Bar in memory is that of Foo, which is recursive, and since recursive aliases are represented as structs this leads to undefined behavior (random crashes).

Now, while fixing this I realized recursive aliases are not needed in the language but until (and if) we remove recursive aliases this fixes those bugs, and also fixes potential bugs regarding tuples.

@asterite asterite self-assigned this Oct 20, 2017
@akzhan
Copy link
Contributor

akzhan commented Oct 23, 2017

LGTM

@RX14 RX14 added this to the Next milestone Oct 23, 2017
@RX14 RX14 merged commit 07d50be into crystal-lang:master Oct 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants