Skip to content

Handle parsing tuples of tuples in tags #775

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

Merged
merged 3 commits into from
Mar 15, 2025

Conversation

apiology
Copy link
Contributor

No description provided.

@@ -241,7 +241,7 @@ def parse *strings, partial: false
paren_stack += 1
elsif char == ')'
paren_stack -= 1
subtype_string += char if paren_stack == 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There wasn't much in the commit log - if you remember why this was there, happy to add more specs and ensure they pass as well.

Copy link
Owner

Choose a reason for hiding this comment

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

If I remember correctly, that condition was a quick fix for some wonky issue with the first iteration of type parameter support. It was seven years ago, so the specifics are lost to me. 🤷 Given the many examples of parametrized types in the specs, I'm plenty confident this won't introduce a regression.

it 'parses tuples of tuples with same type twice in a row' do
api_map = Solargraph::ApiMap.new
type = Solargraph::ComplexType.parse('Array(Symbol, String, Array(Integer, Integer))')
expect(type.to_s).to eq('Array(Symbol, String, Array(Integer, Integer))')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The (Integer, Integer) here does collapse into (Integer) at some point between here and appearing in my LSP results. I'll chase this down next and either add this to the same PR or push a new one if you get to this first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, the qualify() method in UniqueType was applying .uniq, assuming that every list of types represented a union type. Fixed.

@apiology
Copy link
Contributor Author

These bugfixes knock out a batch of strict typechecking issues.

Looks like we'll still need:

  • something to resolve the #[] and #[]= calls with to the right type when we have a literal integer argument
  • multiple assignment and destructuring support
  • support for treating literals like tuples when they have heterogeneous types (?)

I also suspect translating Array() to Tuple() is when we parse it is probably a good idea. It'll help us stay aligned with RBS standard type names and also pull in anything useful we can from those definitions.

Let me know if you have thoughts on any of the above! I think this change can be independent of any of the above, though; it doesn't make anything worse to my knowledge and at least helps humans understand the types without garbling them for the moment.

@castwide
Copy link
Owner

These bugfixes knock out a batch of strict typechecking issues.

Looks like we'll still need:

* something to resolve the #[] and #[]= calls with to the right type when we have a literal integer argument

* multiple assignment and destructuring support

* support for treating literals like tuples when they have heterogeneous types (?)

I also suspect translating Array() to Tuple() is when we parse it is probably a good idea. It'll help us stay aligned with RBS standard type names and also pull in anything useful we can from those definitions.

Let me know if you have thoughts on any of the above! I think this change can be independent of any of the above, though; it doesn't make anything worse to my knowledge and at least helps humans understand the types without garbling them for the moment.

Sounds good to me. Generics and enhanced parameter support have opened a lot of possibilities. Thanks! 💯 :shipit:

@castwide castwide merged commit 779d618 into castwide:master Mar 15, 2025
9 checks passed
apiology added a commit to apiology/solargraph that referenced this pull request Mar 25, 2025
castwide pushed a commit that referenced this pull request Mar 25, 2025
apiology added a commit to apiology/solargraph that referenced this pull request Apr 6, 2025
castwide added a commit that referenced this pull request Apr 15, 2025
* Retire more RubyVM-specific code

* Add basic plugin integration testing (#798)

* Add basic plugin integration testing

Add a GitHub Actions workflow to run very basic smoke tests
for solargraph-rails and solargraph rspec (typechecking and then
running solargraph's specs with it installed and configured)

Also:

* Document solargraph-rspec as a plugin in README.md

* Add solargraph-rspec to .Gemfile as well

* Fix YAML syntax

* Fix GitHub workflow syntax

* Fix GitHub workflow syntax

* Fix GitHub workflow syntax

* Fix GitHub workflow syntax

* Switch yq syntax for the *other* yq, cache apt installation

* Switch yq syntax for the *other* yq, cache apt installation

* Restore Legacy module for solargraph-rails backwards compatibility

* Infer block-pass symbols (#793)

* BlockSymbol link

* First iteration of block-pass symbol resolution

* Chain::Call#block

* Superfluous block tracking

* Refactor NodeChainer

* Fix chain block check

* Sync with #780

* BlockSymbol link

* First iteration of block-pass symbol resolution

* Change spec to test Call#block

* Resolve generics from BlockSymbol

* More annotations in Solargraph code (#801)

* More annotations in Solargraph code

* More annotations from strict typechecking

* More internal annotations

* Add some method overloads

* Add #to_rbs methods to pins, use for better .inspect() output (#789)

* Add #to_rbs methods to pins, use for better .inspect() output

* Add inspect() to Chain::Link, to_rbs to Pin::Namespace

* Fix typo

* Show variable assignments in #desc

* Method generics resolution via argument types (#794)

* Improve block handling in signature selection

Fixes #777

* Resolve method generics

* Track generics in method signatures from RBS and YARD

* Erase method generics that couldn't be resolved

* Refactor Pin#resolve_types to use Pin#transform_types

* Fix issues with UniqueType#transform()

* Cleanups

* Move to keyword parameters for resolved_generic_values

* Add type erasure, method pin rewrite code

* Populate Method parameter/return_type/block from signature

* Mark completed TODOs

* Ruby 3.0 compatibility

* Add erase_generics() to ComplexType::TypeMethods

* TODO -> @todo

* Resolve some TODOs

* Resolve TODOs

* Revert accidental change

* Bring back spec

* Provide full tag to get_method_stack() for better inference

* Fix a missed spot referring to allowlist

* Ensure Signature#generics is not nil

* Various #to_rbs and #inspect improvements

* Clean up code

* Drop accidental addition

* Improve RBS generation from UniqueType

* Use rooted names when generating RBS when available

* Drop bad documentation

* Remove deprecated commands (#790)

* Cache command

* Add :if support to NodeChainer for if statements as lvalues (#805)

* Add :if support to NodeChainer for if statements as lvalues

* Add :if support to NodeChainer for if statements as lvalues

* Fix ApiMap::Cache (#806)

* Fix ApiMap::Cache

* Refactoring

* Gems command

* Various DocMap improvements (#807)

* Retire dead DocMap-related code, restore 'solargraph uncache'

* Best-effort work to support bundler's 'path:' directive in Gemfiles

* Restore support for 'solargraph uncache'

* Clarify names in DocMap

* Tell Thor to exit with status 1 on error, inc. deprecated command

* Clarify shell deprecation messages

* Send deprecation errors to stderr

* Fix merge

* Async gem caching (#809)

* Various regression and future-feature specs (#800)

* Various regression and future-feature specs

* Merge remote-tracking branch 'origin/master' into more_specs

* Another batch of specs

* Drop duplicated spec

* Various regression and future-feature specs

* Various regression and future-feature specs

* Resolve a small issue found on merge

* Fix pre-mature marking of spec as ready

* Unify method generics resolution (#810)

* Map mixins from RBS (#808)

* Map mixins from RBS

* DRY mixin processing

* Fix issue with wrong signature selection by call with block node (#815)

We were picking the wrong signature for Enumerator#select and
Enumerator#find because Chain::Call didn't have access to the block
that was passed in and didn't think the arity matched as a result.

* Keep gem pins in memory (#811)

* Keep gem pins in memory

* DocMap warns on unresolved paths

* Fic cache errors

* Keep stdlib pins in memory

* Move logs for pins in memory from info to debug

* Use previous stdlib memory cache

* Use cursor node in clip cache index

* Changelog

* Add more internal type annotations required by strict typechecking (#814)

* Add more internal type annotations required by strict typechecking

* Add more internal type annotations required by strict typechecking

* Fix types in existing annotations

* Fix names in existing annotations

* Add more internal type annotations required by strict typechecking

* Add more internal type annotations required by strict typechecking

* Disable ApiMap clip cache (#817)

* Refactor gems command (#816)

* Use return type of literal blocks in inference (#818)

* Use simple return type of literal blocks in inference

Also:
* Document block symbol handling issue
* Add failing spec for less trivial literal block inference

* Mark spec as working after merging in latest master

* Add Thread::Mutex#synchronize spec just to be sure

* Fix an internal return type annotation

* Insert Module methods (#820)

* ApiMap#get_methods includes Module

* Redundant code

* Another test

* Fix kwoptarg string in Parameter#to_rbs (#822)

* Revise documentation formatting (#823)

* Revise documentation formatting

* Ruby 3.0 compatibility

* Changelog

* DocMap logging (#825)

* Clean up DocMap logging

* Remove stale requires and autoloads

* Redundant `require 'set'`

* Test redundant require

* Ignore test in Ruby < 3.1.1

* Stub test

* Require set at root and suppress warning

* Remove workaround for now-fixed ComplexType.parse limitations (#827)

Parser bug was fixed in #775

* Add annotations needed for strict typechecking of solargraph code (#828)

* Rescue exceptions in docstring parsing (#830)

* Update README

* Reject nil requires in live code (#831)

* DocMap rejects nil requires

* Handle empty requires

* RbsMap adds mixins to current namespace (#832)

* RbsMap adds mixins to current namespace

* Smoke test

* Release 0.53.1

* Fix a self-type-related false-positive in strict typechecking (#834)

* DocMap fetches gem dependencies (#835)

* Use configured command path to spawn solargraph processes (#837)

* Release 0.53.2

* Remove redundant core fills (#824)

* Remove Errno core fills

* Retire CoreSigns

* Retire MISSING core fills

* Remove implicit .new pins

* Stale specs

* Switch Class#new to [Caller]#initialize for arity checks

* Remove implicit .new pins from source maps

* Resolve self type in variable assignments (#839)

* Eliminate splat-related false-alarms in strict typechecking (#840)

* Dynamic block binding with yieldreceiver (#842)

* Rebind with yieldreceiver

* Unused rebindable_method_names

* Refactor Block#binder_or_nil

* Resolve generics by descending through context type (#847)

* Release 0.53.3

* [regression] Restore 'Unresolved call' typecheck for stdlib objects (#849)

The 'Unresolved call to' typecheck suppresses warnings for calls
against non-RBS-origin pins.  However, the labeling assigning :rbs as
the source of pins from conversions.rb was recently removed as part of
an unrelated cleanup.

* Lazy dynamic rebinding (#851)

* Lazy dynamic rebinding

* Stub failing test

* Move rebinding to Clip

* Restore fill for Class#allocate (#848)

* [regression] Ensure YardMap gems have return type for Class<T>.new (#850)

* [regression] Ensure YardMap gems have return type for Class<T>.new

* Handle self return-type-setting at lower level

* Fix bug where signature return type was based only on annotation

* Create implicit .new pins in namespace method queries (#853)

* Create implicit .new pins in namespace method queries

* Comment for Host#locate_pins exception

* Release 0.53.3

* Use logger in Solargraph::YardMap::Mapper spec

* Add support for simple block argument destructuring (#821)

* Add support for simple block argument destructuring

* Add spec for Array<Array(String, Integer)>#each

* Internal typechecking-driven annotations and code changes (#838)

* Internal typechecking-driven annotations and code changes

* Add @todo for predicate method return type issue

* Internal typechecking-driven annotations and code changes

* Benchmark the typecheck command (#852)

* Enable passing tests (#854)

* Send Gem Caching Progress Notifications to LSP Clients (#855)

* Send gem caching notifications

* LanguageServer::Progress

* DRY progress notifications

* Refactor

* added failing tests (#573)

* [breaking] Fix more complex_type_spec.rb cases (#813)

* [breaking] Fix more complex_type_spec.rb cases

* Consolidate the code that generates substrings to a single place
* Clean up more paths to pass through 'rooted' flag unchanged
* [breaking] Drop special-case interpretation of, e.g., `Array<(String)>` as
  'one element tuple' for future consistency with
  https://yardoc.org/types

  * (String) is a one element tuple in https://yardoc.org/types
  * <String> is an array of zero or more Strings in https://yardoc.org/types
  * Array<(String)> could be an Array of one-element tuples or a
    one element tuple.  https://yardoc.org/types treats it
    as the former.
  * Array<(String), Integer> is not ambiguous if we accept
    (String) as a tuple type, but not currently understood
    by Solargraph.

* Close out complex_type_spec @todos for better RBS output

* Simplify qualify() with transform()

* Resolve merge issue

* Mass assignment support - e.g., a, b = ['1', '2'] (#843)

* Memoize result of Chain#infer (#857)

* Memoize result of Chain#infer

* Add links to cache key

* Add node.location separately to cache key

https://github.com/whitequark/ast/blob/master/lib/ast/node.rb

https://github.com/whitequark/parser/blob/05b88aa0468ce29dfa21e1aff2f0506b1d5d82e1/lib/parser/ast/node.rb#L17

Parser::AST adds 'location' in Parser::AST::Node to its superclass
AST::Node, but doesn't overwrite the #hash and #eql? methods

* Fall back to using links.map(&:word)

* Implement eql? and hash for ApiMap for cache coherency

* Remove @cache from ApiMap#equality_fields

* Remove clip caches (#860)

* Add rbs_collection to maps (#858)

* Fix flaky rename specs (#869)

* Ignore malformed mixins and overloads (#862)

* Ignore malformed mixins

* Ignore malformed overload tags

* Add internal type annotations needed for strict-level typechecking (#865)

* Add internal type annotations needed for strict-level typechecking

* Fix annotations

* Add internal type annotations needed for strict-level typechecking

* Fix flaky rename specs

* Move to untyped as Hash value

---------

Co-authored-by: Fred Snyder <[email protected]>

* Drop Parser::ParserGem::ClassMethods#returns_from_node (#866)

* Refactor TypeChecker#argument_problems_for for type safety (#867)

* Refactor TypeChecker#argument_problems_for for type safety

This should put it in a state that it can pass type checking once we
have another feature or two

* Editor compatibility hack

* Fix class name

* Fix flaky rename specs

---------

Co-authored-by: Fred Snyder <[email protected]>

* Specify more type behavior for variable reassignment (#863)

* One-step source synchronization (#871)

* One-step source synchronization

* Synchronize libraries

* Fix progress notification timing (#873)

* Show cache progress in shell commands (#874)

* Show cache progress in shell commands

* Typecheck error

---------

Co-authored-by: Fred Snyder <[email protected]>
Co-authored-by: BonitaTerror <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants