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

Type constant parts #247

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions lib/steep/type_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1311,16 +1311,26 @@ def synthesize(node, hint: nil)
when :self
add_typing node, type: AST::Types::Self.new

when :cbase
add_typing node, type: AST::Types::Void.new

when :const
const_name = module_name_from_node(node)
parent = node.children[0]
if parent
_, constr = synthesize(parent)
else
constr = self
end

const_name = constr.module_name_from_node(node)

if const_name
type = type_env.get(const: const_name) do
fallback_to_any node
constr.fallback_to_any(node)
end
add_typing node, type: type
constr.add_typing(node, type: type)
else
fallback_to_any node
constr.fallback_to_any(node)
end

when :casgn
Expand Down
29 changes: 29 additions & 0 deletions test/type_construction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6239,4 +6239,33 @@ def foo: () -> String123
end
end
end

def test_const
with_checker(<<RBS) do |checker|
class Nested
module Consta
class Nt
end
end
end
RBS
source = parse_ruby(<<-RUBY)
::Nested::Consta::Nt
Nested::Consta::Nt
RUBY

with_standard_construction(checker, source) do |construction, typing|
construction.synthesize(source.node)

typing.type_of(node: dig(source.node, 0, 0, 0, 0))
typing.type_of(node: dig(source.node, 0, 0, 0))
typing.type_of(node: dig(source.node, 0, 0))
typing.type_of(node: dig(source.node, 0))

typing.type_of(node: dig(source.node, 1, 0, 0))
typing.type_of(node: dig(source.node, 1, 0))
typing.type_of(node: dig(source.node, 1))
end
end
end
end