Skip to content

Improve typechecking of generics - #1012

Closed
apiology wants to merge 115 commits into
castwide:masterfrom
apiology:generic_typechecking_improvements
Closed

apiology wants to merge 115 commits into
castwide:masterfrom
apiology:generic_typechecking_improvements

Conversation

@apiology

@apiology apiology commented Jul 18, 2025

Copy link
Copy Markdown
Contributor

There are a lot of files changed here, but the vast majority are added specs and fixed annotations, most from the improvements in this PR.

This is a rewrite of the current 'can I use this type here' code. In particular, we now in strong mode validate the type parameters of variable assignment and parameters, with the following exceptions:

image

Info on each check:

image

Depends on:

Includes for convenience:

@apiology
apiology marked this pull request as draft July 18, 2025 22:38
end

# @return [Hash{String => Array<String>}]
# @return [Hash{String => Array<Pin::Reference::Include>}]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The better typechecking found some issues in the annotations!

elsif return_type.erased_version_of?(other.return_type)
other.return_type
elsif other.return_type.erased_version_of?(return_type)
return_type

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Help more precise type definitions make it through as the pins we typecheck against

generic_values = type.all_params.map(&:to_s)
include_pin = Solargraph::Pin::Reference::Include.new(
name: decl.name.relative!.to_s,
name: type.rooted_name,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

build_type takes care of any root information we have available

@apiology

apiology commented Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged into v0.59 release branch

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