Improve error messages when typealiases fail to check (#1914)

This adds the typealias' usage site to the stack frame.
This commit is contained in:
Daniel Chao authored and GitHub committed 2026-10-19 12:34:04 -07:00
1 parent 97c73e7c28
commit 08f0c3781b
12 files changed
+68 -3

No files matched your search

@@ -2458,18 +2458,39 @@ public abstract class TypeNode extends PklNode {
}
protected Object executeLazily(VirtualFrame frame, Object value) {
return aliasedTypeNode.executeLazily(frame, value);
try {
return aliasedTypeNode.executeLazily(frame, value);
} catch (VmTypeMismatchException e) {
throw withInsertedStackFrame(e);
}
}
/** See docstring on {@link TypeAliasTypeNode#executeLazily}. */
@Override
public Object executeEagerly(VirtualFrame frame, Object value) {
return aliasedTypeNode.executeEagerly(frame, value);
try {
return aliasedTypeNode.executeEagerly(frame, value);
} catch (VmTypeMismatchException e) {
throw withInsertedStackFrame(e);
}
}
@Override
public Object executeAndSet(VirtualFrame frame, Object value) {
return aliasedTypeNode.executeAndSet(frame, value);
try {
return aliasedTypeNode.executeAndSet(frame, value);
} catch (VmTypeMismatchException e) {
throw withInsertedStackFrame(e);
}
}
@TruffleBoundary
private VmTypeMismatchException withInsertedStackFrame(VmTypeMismatchException e) {
// include the typealias usage site in the call stack
e.putInsertedStackFrame(
getRootNode().getCallTarget(),
VmUtils.createStackFrame(sourceSection, getRootNode().getName()));
return e;
}
@TruffleBoundary
@@ -10,6 +10,10 @@ xxxx | typealias Uri = String(isValidUrl)
^^^^^^^^^^
at pkl.analyze#importGraph (pkl:base)
xx | external function importGraph(moduleUris: Set<Uri>): ImportGraph
^^^
at pkl.analyze#importGraph (pkl:analyze)
x | result = analyze.importGraph(Set("foo <>"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at analyzeInvalidModuleUri#result (file:///$snippetsDir/input/errors/analyzeInvalidModuleUri.pkl)
@@ -10,6 +10,10 @@ xxxx | typealias Uri = String(isValidUrl)
^^^^^^^^^^
at pkl.analyze#importGraph (pkl:base)
xx | external function importGraph(moduleUris: Set<Uri>): ImportGraph
^^^
at pkl.analyze#importGraph (pkl:analyze)
x | result = analyze.importGraph(Set("foo.pkl"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at analyzeRelativeModuleUri#result (file:///$snippetsDir/input/errors/analyzeRelativeModuleUri.pkl)
@@ -6,6 +6,10 @@ x | typealias Ref<T> = ref.Reference<D, T>
^^^^^^^^^^^^^^^^^^^
at reference1#test (file:///$snippetsDir/input/errors/reference1.pkl)
x | test = ref.Reference(d, String, "") as Ref<Int>
^^^^^^^^
at reference1#test (file:///$snippetsDir/input/errors/reference1.pkl)
xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base)
@@ -6,6 +6,10 @@ x | typealias Ref<T> = ref.Reference<D, T>
^^^^^^^^^^^^^^^^^^^
at reference2#test (file:///$snippetsDir/input/errors/reference2.pkl)
x | test = ref.Reference(d, String, "") as Ref<Boolean | Int>
^^^^^^^^^^^^^^^^^^
at reference2#test (file:///$snippetsDir/input/errors/reference2.pkl)
xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base)
@@ -6,6 +6,10 @@ x | typealias Ref<T> = ref.Reference<D, T>
^^^^^^^^^^^^^^^^^^^
at reference3#test (file:///$snippetsDir/input/errors/reference3.pkl)
x | test = ref.Reference(d, String, "") as Ref<Listing<String>>
^^^^^^^^^^^^^^^^^^^^
at reference3#test (file:///$snippetsDir/input/errors/reference3.pkl)
xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base)
@@ -6,6 +6,10 @@ x | typealias Ref<T> = ref.Reference<D, T>
^^^^^^^^^^^^^^^^^^^
at reference4#test (file:///$snippetsDir/input/errors/reference4.pkl)
x | test = ref.Reference(d, String, "") as Ref<Alias1>
^^^^^^^^^^^
at reference4#test (file:///$snippetsDir/input/errors/reference4.pkl)
xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base)
@@ -6,6 +6,10 @@ x | typealias Ref<T> = ref.Reference<D, T>
^^^^^^^^^^^^^^^^^^^
at reference5#test (file:///$snippetsDir/input/errors/reference5.pkl)
xx | test = ref.Reference(d2, String, "") as Ref<String>
^^^^^^^^^^^
at reference5#test (file:///$snippetsDir/input/errors/reference5.pkl)
xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base)
@@ -10,6 +10,10 @@ xxxx | typealias Uri = String(isValidUrl)
^^^^^^^^^^
at pkl.EvaluatorSettings#resolve (pkl:base)
xxx | function resolve(enclosingUri: Uri): EvaluatorSettings =
^^^
at pkl.EvaluatorSettings#resolve (pkl:EvaluatorSettings)
xxx | fixed resolvedEvaluatorSettings: EvaluatorSettingsModule = evaluatorSettings.resolve(projectFileUri)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.Project#resolvedEvaluatorSettings (pkl:Project)
@@ -7,6 +7,10 @@ at classTypeErr11#res22 (file:///$snippetsDir/input/types/classType.pkl)
A `Class` type check can only succeed when its type argument is an un-parameterized class, `unknown`, `module`, `this`, or an alias to one of those types.
x | res22 = List(A, C) as F<A | B>
^^^^^^^^
at classTypeErr11#res22 (file:///$snippetsDir/input/types/classTypeErr11.pkl)
xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base)
@@ -7,6 +7,10 @@ at classTypeErr12#res22 (file:///$snippetsDir/input/types/classType.pkl)
A `Class` type check can only succeed when its type argument is an un-parameterized class, `unknown`, `module`, `this`, or an alias to one of those types.
x | res22 = List(A, C) as G<A | B>
^^^^^^^^
at classTypeErr12#res22 (file:///$snippetsDir/input/types/classTypeErr12.pkl)
xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base)
@@ -7,6 +7,10 @@ at classTypeErr13#res22 (file:///$snippetsDir/input/types/classType.pkl)
A `Class` type check can only succeed when its type argument is an un-parameterized class, `unknown`, `module`, `this`, or an alias to one of those types.
x | res22 = List(A, C) as G<A>
^^^^
at classTypeErr13#res22 (file:///$snippetsDir/input/types/classTypeErr13.pkl)
xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base)