Skip to content

Fix TopLevelVisitor adding existing ClassDef type to current scope#15067

Merged
straight-shoota merged 1 commit intocrystal-lang:masterfrom
straight-shoota:fix/class_def-scope-type
Oct 8, 2024
Merged

Fix TopLevelVisitor adding existing ClassDef type to current scope#15067
straight-shoota merged 1 commit intocrystal-lang:masterfrom
straight-shoota:fix/class_def-scope-type

Conversation

@straight-shoota
Copy link
Member

@straight-shoota straight-shoota commented Oct 7, 2024

When a type is reopened, the compiler adds it as nested type to the current scope (i.e. where it's reopened). That's wrong because the reopened type is already scoped to the location of the original location and this could lead to cycles.

For example, the following program would crash the compiler with an infinite recursion:

class Foo
  alias Bar = Foo

  class Bar
  end
end

This fix makes sure to only add newly defined types to the current scope, not reopened ones. All other visitor methods which defined types already do this, only ClassDef was unconditionally adding to the current scope.

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels Oct 7, 2024
@straight-shoota straight-shoota self-assigned this Oct 7, 2024
@straight-shoota straight-shoota modified the milestones: 1.15.0, 1.14.0 Oct 8, 2024
@straight-shoota straight-shoota merged commit dddc0dc into crystal-lang:master Oct 8, 2024
@straight-shoota straight-shoota deleted the fix/class_def-scope-type branch October 8, 2024 15:06
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.

2 participants