-
Notifications
You must be signed in to change notification settings - Fork 962
Improve recursion identity for direct type instantiations #3445
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
Changes from 1 commit
08f1491
020d921
e4bcd52
586394c
bcfcae8
668feed
9f79d71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22739,7 +22739,7 @@ func (c *Checker) getTypeFromClassOrInterfaceReference(node *ast.Node, symbol *a | |
| // of the class or interface. | ||
| localTypeArguments := c.fillMissingTypeArguments(c.getTypeArgumentsFromNode(node), typeParameters, minTypeArgumentCount, isJs) | ||
| typeArguments := append(d.OuterTypeParameters(), localTypeArguments...) | ||
| return c.createTypeReference(t, typeArguments) | ||
| return c.createTypeReferenceEx(t, typeArguments, ObjectFlagsFromTypeNode) | ||
| } | ||
| if c.checkNoTypeArguments(node, symbol) { | ||
| return t | ||
|
|
@@ -23660,7 +23660,11 @@ func (c *Checker) getTypeFromArrayOrTupleTypeNode(node *ast.Node) *Type { | |
| } else { | ||
| elementTypes = core.Map(node.Elements(), c.getTypeFromTypeNode) | ||
| } | ||
| links.resolvedType = c.createNormalizedTypeReference(target, elementTypes) | ||
| if target.objectFlags&ObjectFlagsTuple != 0 { | ||
| links.resolvedType = c.createNormalizedTupleType(target, elementTypes) | ||
| } else { | ||
| links.resolvedType = c.createTypeReferenceEx(target, elementTypes, ObjectFlagsFromTypeNode) | ||
| } | ||
| } | ||
| } | ||
| return links.resolvedType | ||
|
|
@@ -24623,13 +24627,16 @@ func (c *Checker) tryCreateTypeReference(target *Type, typeArguments []*Type) *T | |
| } | ||
|
|
||
| func (c *Checker) createTypeReference(target *Type, typeArguments []*Type) *Type { | ||
| return c.createTypeReferenceEx(target, typeArguments, ObjectFlagsNone) | ||
| } | ||
|
|
||
| func (c *Checker) createTypeReferenceEx(target *Type, typeArguments []*Type, objectFlags ObjectFlags) *Type { | ||
| id := getTypeListKey(typeArguments) | ||
| intf := target.AsInterfaceType() | ||
| if t, ok := intf.instantiations[id]; ok { | ||
| return t | ||
| } | ||
| t := c.newObjectType(ObjectFlagsReference, target.symbol) | ||
| t.objectFlags |= c.getPropagatingFlagsOfTypes(typeArguments, TypeFlagsNone) | ||
| t := c.newObjectType(ObjectFlagsReference|objectFlags|c.getPropagatingFlagsOfTypes(typeArguments, TypeFlagsNone), target.symbol) | ||
|
Comment on lines
24640
to
+24645
|
||
| d := t.AsTypeReference() | ||
| d.target = target | ||
| d.resolvedTypeArguments = typeArguments | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -839,9 +839,11 @@ func getRecursionIdentity(t *Type) RecursionId { | |
| // unique AST node. | ||
| return asRecursionId(t.AsTypeReference().node) | ||
| } | ||
| if t.symbol != nil && !(t.objectFlags&ObjectFlagsAnonymous != 0 && t.symbol.Flags&ast.SymbolFlagsClass != 0) { | ||
| if t.symbol != nil && !(t.objectFlags&ObjectFlagsAnonymous != 0 && t.symbol.Flags&ast.SymbolFlagsClass != 0) && t.objectFlags&ObjectFlagsFromTypeNode == 0 { | ||
| // We track object types that have a symbol by that symbol (representing the origin of the type), but | ||
| // exclude the static side of a class since it shares its symbol with the instance side. | ||
| // exclude the static sides of classes (since they share their symbols with the instance sides) and type | ||
| // references that originate in resolution of AST type nodes (since such type nodes cannot be the source | ||
| // of generative recursion without first being instantiated). | ||
|
Comment on lines
+842
to
+846
|
||
| return asRecursionId(t.symbol) | ||
| } | ||
| if isTupleType(t) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this also accept and propagate
ObjectFlagsFromTypeNode? FWIW, while testing this PR locally I ended up implementing this: https://github.com/microsoft/typescript-go/compare/fix-3426...Andarist:fix/deeply-nested-tuples-from-type-nodes?expand=1There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Andarist Thanks!