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

Better constant typing #529

Merged
merged 3 commits into from
Apr 5, 2022
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
12 changes: 12 additions & 0 deletions lib/steep/type_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2731,6 +2731,14 @@ def synthesize_constant(node, parent_node, constant_name)

return [type, constr, name]
end
when AST::Types::Any
# Couldn't detect the type of the parent constant
# Skip reporting error for this node.
if node
_, constr = add_typing(node, type: parent_type)
end

return [parent_type, constr, nil]
end
end

Expand All @@ -2744,6 +2752,10 @@ def synthesize_constant(node, parent_node, constant_name)
end
end

if node
_, constr = add_typing(node, type: AST::Builtin.any_type)
end

[AST::Builtin.any_type, constr, nil]
end
end
Expand Down
10 changes: 0 additions & 10 deletions smoke/diagnostics/test_expectations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -557,16 +557,6 @@
severity: ERROR
message: 'Cannot find the declaration of constant: `FOO`'
code: Ruby::UnknownConstant
- range:
start:
line: 4
character: 7
end:
line: 4
character: 10
severity: ERROR
message: 'Cannot find the declaration of constant: `BAR`'
code: Ruby::UnknownConstant
- range:
start:
line: 6
Expand Down
59 changes: 55 additions & 4 deletions test/type_construction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7061,7 +7061,7 @@ def test_proc_with_block_annotation
-> (n, &b) do
# @type var n: Integer
# @type var b: nil | ^(Integer) -> String

if b
b[n]
end
Expand Down Expand Up @@ -8169,7 +8169,7 @@ def cdr(list)
list[1]
end
end
end
end

# @type var a: list[Integer]
a = [1, [2, [3, nil]]]
Expand Down Expand Up @@ -8448,7 +8448,7 @@ def foo(callback)
if callback.is_a?(Proc)
callback = callback[]
end