Skip to content

Stop crashing on unsupported anonymous classes - #488

Merged
tjpalmer merged 1 commit into
mainfrom
anonymous-vs-imu
Sep 15, 2026
Merged

tjpalmer merged 1 commit into
mainfrom
anonymous-vs-imu

Conversation

@tjpalmer

Copy link
Copy Markdown
Contributor
  • Fix ImuChecker crash on anonymous class decl #485
  • Don't try to make the syntax work, just stop crashing the whole frontend on it
  • Examples in the repl after these changes, where lonely class {} behavior (entry 0 below) isn't changed this pr:
$ class {}
interactive#0: Anon__0
$ let a = class {};
1: let a = class {};
       
[interactive#1:1+4-5]@G: Missing type info for a__4
1: let a = class {};
   ┗━━━━━━━━━━━━━━┛
[interactive#1:1+0-16]@R: Declaration is malformed
interactive#1: fail

for (child in tree.children) {
if (child is DeclTree) {
child.parts!!.metadataSymbolMap[typeDeclSymbol]?.target
child.parts?.metadataSymbolMap[typeDeclSymbol]?.target

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.

This is the real change, and notice that there were already ? after it. Maybe I was just being overzealous with the !!.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this is happening when it should be there, you can always replaceWithErrorNode(MessageTemplate.MalformedDeclaration) if it doesn't have what it should.

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.

If this is happening when it should be there, you can always replaceWithErrorNode(MessageTemplate.MalformedDeclaration) if it doesn't have what it should.

Thanks for the tip! I'll try to keep that in mind for appropriate use cases. In this case, I figure nobody else was dying on it, so this could shouldn't either.

return__11 = void
});
@typeDecl(Anon__4) @stay @reach(\none) let t#5;
t#5 = type (Anon__4);

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.

I think I managed to get 3 different Anon classes here but none assigned to the names given. We don't have many other examples of anonymous classes, so I'm unsure of our intentions with them.

@typeDecl(Anon__4) @stay @reach(\none) let t#5;
t#5 = type (Anon__4);
let[inconceivable];
error (list("@", "`(Leaf`", "export", "`Leaf)`", "`(Eq`", "`(Leaf`", "let", "decoratedInside", "`Leaf)`", "=", "`Eq)`", "`(At`", "@", "`(Leaf`", "imu", "`Leaf)`", "`(Curly`", "`(Leaf`", "class", "`Leaf)`", "{", "}", "`Curly)`", "`At)`"))

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.

Here's the only place imu shows up in the rendered pseudocode, and I think it comes from the @imu class case in test.temper, and it's fine if we don't want to support that. Mostly, I was just curious what works and what doesn't.

@@ -0,0 +1,13 @@
// Anonymous alone was already getting through the front end
// before starting this test.
class {}

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.

So this doesn't seem to give errors, but the cases below do.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm. I guess this is equivalent to class t#0 {}

export let decorated = class {};

// Including this invalid syntax, just for thinking about.
export let decoratedInside = @imu class {};

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.

Again, this last one is where I think the garbage trees are coming from. And that might be fine.

The key point is that after this PR, we don't hard crash the front end for any of these cases, anymore.

@tjpalmer
tjpalmer marked this pull request as ready for review September 14, 2026 19:16
@@ -0,0 +1,13 @@
// Anonymous alone was already getting through the front end
// before starting this test.
class {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm. I guess this is equivalent to class t#0 {}

for (child in tree.children) {
if (child is DeclTree) {
child.parts!!.metadataSymbolMap[typeDeclSymbol]?.target
child.parts?.metadataSymbolMap[typeDeclSymbol]?.target

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this is happening when it should be there, you can always replaceWithErrorNode(MessageTemplate.MalformedDeclaration) if it doesn't have what it should.

@tjpalmer
tjpalmer merged commit ca32073 into main Sep 15, 2026
2 checks passed
@tjpalmer
tjpalmer deleted the anonymous-vs-imu branch September 15, 2026 21:01
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.

ImuChecker crash on anonymous class decl

2 participants