Skip to content

Conversation

Keno
Copy link
Member

@Keno Keno commented Oct 7, 2025

Currently this is an ErrorException in the runtime/interpreter, but a TypeError in codegen. This is not permitted - which error is thrown is semantically observable and codegen is not permitted to change it. Worse, inference is also inconsistent about whether this is TypeError or ErrorException, so this could actually lead to type confusion and crashes. Fix all that by having the runtime also emit a TypeError here. However, in order to not lose the binding name in the error message, adjust the TypeError context field to permit a binding.

@Keno Keno added the backport 1.12 Change should be backported to release-1.12 label Oct 7, 2025
Comment on lines 94 to 96
elseif isa(ex.context, Core.Binding)
gr = ex.context.globalref
ctx = "in $(ex.func) of global binding `$(gr.mod).$(gr.name)`"
Copy link
Member

Choose a reason for hiding this comment

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

I do not like assuming that br.globalref is reliable, since it both often has the wrong module (it is often the resolved value instead of the original one) and it assumes that every Binding must have been associated with one GlobalRef, but we might want to have Bindings which are not just equivalent to a GlobalRef.

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, I'll switch it to provide a GlobalRef for the original binding.

Currently this is an ErrorException in the runtime/interpreter, but a TypeError
in codegen. This is not permitted - which error is thrown is
semantically observable and codegen is not permitted to change it.
Worse, inference is also inconsistent about whether this is TypeError or
ErrorException, so this could actually lead to type confusion and crashes.
Fix all that by having the runtime also emit a TypeError here. However,
in order to not lose the binding name in the error message, adjust
the TypeError context field to permit a binding.
@Keno Keno force-pushed the kf/assigntypeerror branch from d01041a to 3cebd25 Compare October 7, 2025 15:35
@Keno Keno merged commit 17e0df5 into master Oct 8, 2025
7 checks passed
@Keno Keno deleted the kf/assigntypeerror branch October 8, 2025 15:38
Comment on lines +128 to +129
jl_value_t *gr = jl_module_globalref(mod, sym);
jl_value_t *ex = jl_new_struct(jl_typeerror_type, jl_symbol(fname), gr, expected, got);
Copy link
Member

Choose a reason for hiding this comment

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

Missing GC pushes here (the correctness of your annotations is not checked in this file)

Copy link
Member Author

Choose a reason for hiding this comment

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

Both the symbol and the globalref should be globally rooted here?

Copy link
Member

Choose a reason for hiding this comment

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

both expected and got are marked as unrooted

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I see what you're saying - will fix.

Keno added a commit that referenced this pull request Oct 8, 2025
@Keno Keno mentioned this pull request Oct 8, 2025
Keno added a commit that referenced this pull request Oct 8, 2025
@KristofferC KristofferC mentioned this pull request Oct 10, 2025
47 tasks
KristofferC pushed a commit that referenced this pull request Oct 10, 2025
#59766)

Currently this is an ErrorException in the runtime/interpreter, but a
TypeError in codegen. This is not permitted - which error is thrown is
semantically observable and codegen is not permitted to change it.
Worse, inference is also inconsistent about whether this is TypeError or
ErrorException, so this could actually lead to type confusion and
crashes. Fix all that by having the runtime also emit a TypeError here.
However, in order to not lose the binding name in the error message,
adjust the TypeError context field to permit a binding.

(cherry picked from commit 17e0df5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 1.12 Change should be backported to release-1.12

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants