Skip to content

Commit

Permalink
Merge pull request #1279 from pocke/Validate_duplicate_type_aliases
Browse files Browse the repository at this point in the history
Validate duplicate type aliases
  • Loading branch information
soutaro committed Mar 20, 2023
2 parents 0dd11d3 + 388e6c8 commit c28989d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rbs/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def insert_decl(decl, outer:, namespace:)
name = decl.name.with_prefix(namespace)

if interface_entry = interface_decls[name]
DuplicatedDeclarationError.new(name, decl, interface_entry.decl)
raise DuplicatedDeclarationError.new(name, decl, interface_entry.decl)
end

interface_decls[name] = InterfaceEntry.new(name: name, decl: decl, outer: outer)
Expand All @@ -374,7 +374,7 @@ def insert_decl(decl, outer:, namespace:)
name = decl.name.with_prefix(namespace)

if entry = type_alias_decls[name]
DuplicatedDeclarationError.new(name, decl, entry.decl)
raise DuplicatedDeclarationError.new(name, decl, entry.decl)
end

type_alias_decls[name] = TypeAliasEntry.new(name: name, decl: decl, outer: outer)
Expand Down
30 changes: 30 additions & 0 deletions test/rbs/environment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,36 @@ def test_const_twice_duplication_error
end
end

def test_type_alias_twice_duplication_error
env = Environment.new

_, _, decls = RBS::Parser.parse_signature(<<EOF)
type foo = String
type foo = Integer
EOF

assert_raises RBS::DuplicatedDeclarationError do
env << decls[0]
env << decls[1]
end
end

def test_interface_twice_duplication_error
env = Environment.new

_, _, decls = RBS::Parser.parse_signature(<<EOF)
interface _I
end
interface _I
end
EOF

assert_raises RBS::DuplicatedDeclarationError do
env << decls[0]
env << decls[1]
end
end

def test_generic_class
env = Environment.new

Expand Down

0 comments on commit c28989d

Please sign in to comment.