fix(go): don't emit embeds for interface type-set constraints#1818
Open
Synvoya wants to merge 1 commit into
Open
fix(go): don't emit embeds for interface type-set constraints#1818Synvoya wants to merge 1 commit into
Synvoya wants to merge 1 commit into
Conversation
An interface type_elem that is a generics type-set constraint - a union
(`A | B`) or an approximation (`~T`) - was walked like an embedded
interface, so each non-predeclared term produced an `embeds` heritage
edge (e.g. `type Number interface { MyInt | MyFloat }` emitted
Number->MyInt and Number->MyFloat embeds).
Go only embeds a lone interface type, and each embed is its own element;
union/approximation terms are a constraint type set that can never be
embedded, so those edges assert composition that does not exist. Detect
type-set elems (a `|` or `negated_type` child) and reclassify their
terms as `references` (context=type_constraint), preserving the type
link without the false heritage edge. Genuine interface embedding
(single/qualified/generic interface terms) is unchanged.
Adds regression coverage: positive guards for struct and interface
embedding, plus a negative control asserting union terms are not embeds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Go extractor treats every interface
type_elemas an embedded interface.But a Go type-set constraint (generics) is not embedding — a union
A | Bor an approximation~Tis a set of type terms, and Go only everembeds a lone interface type. Because the branch walked union terms the same
way it walks an embedded interface, each non-predeclared term produced a
spurious
embedsheritage edge.Reproduction on
v8HEADextract_goemits:embedsis a heritage relation (grouped withinherits/implements/mixes_ininextract.py), so this asserts a composition/method-promotionrelationship that does not exist —
Numbercannot embed the concrete typesMyInt/MyFloat; they are constraint terms. This pollutes heritage queriesover the graph with false edges.
Fix
Detect a type-set
type_elem(it has a|or anegated_typechild — bothtokens appear only in constraint position, never in embedding) and reclassify
its terms as
references(context="type_constraint") instead ofembeds.This keeps the type link but drops the false heritage claim. The edge count is
unchanged; only the relation/context is corrected.
Genuine interface embedding is untouched — a lone interface term
(
Reader,io.Reader,Sortable[int]) has no|/~, so it still emitsembeds.Tests
Added to
tests/test_languages.py:test_go_interface_type_union_is_not_embedding— negative control:union terms must not be
embeds, and are present asreferences/type_constraint. Fails on HEAD (asserts the spuriousNumber->MyIntembed away), passes with the fix.test_go_interface_embedding_emits_embeds/test_go_struct_embedding_emits_embeds— positive guards that genuineembedding on the existing
sample.gofixture (ReaderLoggerembedsLogger/Reader;DataProcessorembedsBaseProcessor) still works.python3 -m pytest tests/test_languages.py -q→317 passed, 13 skipped(the 13 skips are the optional
tree-sitter-dmgrammar). No behavior changeoutside Go interface type-set constraints.