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

Improve detection of instance variables in extended modules #10554

Merged

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Mar 26, 2021

Resolves #9568. This improves upon the current situation in two ways:

  • The compiler currently doesn't detect instance variables that are declared with no types, i.e. whose types are deduced from their assignments. This PR adds support for these variables.
  • The extending type is now shown in the error messages. This works even for chains of included types:
    module Foo
      @x : Int32? # Error: can't declare instance variables in Foo because Baz extends it
    end
    
    module Bar
      include Foo
    end
    
    module Baz
      extend Bar
    end
    The old message would have been can't declare instance variables in Baz:Module.

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels Apr 14, 2021
Copy link
Member

@beta-ziliani beta-ziliani left a comment

Choose a reason for hiding this comment

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

Thanks @HertzDevil !

@beta-ziliani beta-ziliani added this to the 1.2.0 milestone Aug 10, 2021
@straight-shoota straight-shoota merged commit bd1d856 into crystal-lang:master Aug 12, 2021
@HertzDevil HertzDevil deleted the bug/extended-module-ivar branch August 12, 2021 12:19
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.

BUG: Class doesn't implement instance_vars (Exception)
3 participants