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

Check file-private types for abstract defs and recursive structs #11838

Merged

Conversation

HertzDevil
Copy link
Contributor

Unimplemented abstract defs of file-private types do not trigger a compilation error until they are called:

private abstract class Foo
  abstract def foo
end

class Bar < Foo
  # should not compile
end

Recursive value types do not trigger compilation errors at all:

private struct Foo
  def initialize(@x : Foo?)
  end
end

Foo.new(Foo.new(nil)) # Invalid memory access (signal 11) at address 0x0

This happens because both Crystal::AbstractDefChecker and Crystal::RecursiveStructChecker only look at types reachable from the top-level namespace (i.e. the Crystal::Program instance); this PR adds checks for the namespaces associated with each file-private scope.

@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels Feb 17, 2022
Copy link
Member

@asterite asterite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant!

@oprypin oprypin added this to the 1.4.0 milestone Feb 20, 2022
@straight-shoota straight-shoota merged commit a978a06 into crystal-lang:master Feb 22, 2022
@HertzDevil HertzDevil deleted the bug/private-type-errors branch February 24, 2022 16:34
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:semantic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants