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

Validate duplicate type aliases #1279

Merged
merged 2 commits into from
Mar 20, 2023

Conversation

pocke
Copy link
Member

@pocke pocke commented Mar 16, 2023

An environment should reject duplicate type aliases, but actually, it just ignores the duplication due to a forgotten raise.

This PR fixes the validation to raise an error on duplicate type aliases, like the following.

type foo = String
type foo = Integer

Additional Information

Interface has the same problem.

rbs/lib/rbs/environment.rb

Lines 364 to 371 in 0dd11d3

when AST::Declarations::Interface
name = decl.name.with_prefix(namespace)
if interface_entry = interface_decls[name]
DuplicatedDeclarationError.new(name, decl, interface_entry.decl)
end
interface_decls[name] = InterfaceEntry.new(name: name, decl: decl, outer: outer)

For example, the second _I conceals the first one in the following example.

interface _I
  def foo: () -> void
end

interface _I
  def bar: () -> void
end

module M
  include _I
end

We can confirm this problem with the following command.

# It should print `foo` and `bar`,
# but actually it prints only `bar`.
$ rbs -I. methods --no-inherit M
bar (public)

I think the interface should behave the same as the open class, instead of rejecting duplicated interfaces.
I will create a PR to fix the interface problem soon.

@pocke
Copy link
Member Author

pocke commented Mar 17, 2023

I and @soutaro discussed duplicated interfaces. It should cause an error also.
So I made it causes a duplication error on interfaces too. 388e6c8

Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

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

Thanks! 💦

@soutaro soutaro added this pull request to the merge queue Mar 20, 2023
@soutaro soutaro added this to the RBS 3.1 milestone Mar 20, 2023
@soutaro soutaro merged commit c28989d into ruby:master Mar 20, 2023
@pocke pocke deleted the Validate_duplicate_type_aliases branch March 20, 2023 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants