Skip to content

Commit

Permalink
Merge pull request #1301 from soutaro/backports-1.8
Browse files Browse the repository at this point in the history
Backports #1300 and #1299
  • Loading branch information
soutaro authored Oct 29, 2024
2 parents eb36e54 + 721372c commit 7930cb9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
5 changes: 2 additions & 3 deletions lib/steep/server/master.rb
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,9 @@ def process_message_from_client(message)
controller.push_changes(path)

case type
when 1, 2
when LSP::Constant::FileChangeType::CREATED, LSP::Constant::FileChangeType::CHANGED
content = path.read
when 4
# Deleted
when LSP::Constant::FileChangeType::DELETED
content = ""
end

Expand Down
8 changes: 4 additions & 4 deletions lib/steep/type_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1434,10 +1434,10 @@ def synthesize(node, hint: nil, condition: false)
case hint
when AST::Types::Any, AST::Types::Top, AST::Types::Void
# ok
when hint == pair.type
# ok
else
pair.constr.typing.add_error Diagnostic::Ruby::FallbackAny.new(node: node)
unless hint == pair.type
pair.constr.typing.add_error Diagnostic::Ruby::FallbackAny.new(node: node)
end
end
end
end
Expand Down Expand Up @@ -5054,7 +5054,7 @@ def pick_one_of(types)
if (type_, constr = yield(type, constr))
constr.check_relation(sub_type: type_, super_type: type).then do
constr = constr.save_typing
return Pair.new(type: type, constr: constr)
return Pair.new(type: type_, constr: constr)
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions sig/shims/language-server_protocol.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ module LanguageServer
end

TextDocumentSyncKind: __todo__

module FileChangeType
CREATED: 1
CHANGED: 2
DELETED: 3

type t = 1 | 2 | 3
end
end

module Interface
Expand Down
2 changes: 1 addition & 1 deletion sig/steep/type_construction.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ module Steep
#
def type_hash: (Parser::AST::Node hash_node, hint: AST::Types::t?) -> Pair

# Returns the first one from elements of `types` that returns a type `t` where `t <: hint`.
# Yield each member included in `types` and returns the first one where the type `<:` hint
#
def pick_one_of: (Array[AST::Types::t] types) { (AST::Types::t hint, TypeConstruction) -> Pair? } -> Pair?

Expand Down
19 changes: 19 additions & 0 deletions test/type_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2400,4 +2400,23 @@ def test_record_type__keys
YAML
)
end

def test_untyped_hash
run_type_check_test(
signatures: {
"a.rbs" => <<~RBS
RBS
},
code: {
"a.rb" => <<~RUBY
{ foo: 1} #: Hash[untyped, untyped] | String
RUBY
},
expectations: <<~YAML
---
- file: a.rb
diagnostics: []
YAML
)
end
end

0 comments on commit 7930cb9

Please sign in to comment.