Stop crashing on unsupported anonymous classes - #488
Conversation
Signed-off-by: Tom <[email protected]>
| for (child in tree.children) { | ||
| if (child is DeclTree) { | ||
| child.parts!!.metadataSymbolMap[typeDeclSymbol]?.target | ||
| child.parts?.metadataSymbolMap[typeDeclSymbol]?.target |
There was a problem hiding this comment.
This is the real change, and notice that there were already ? after it. Maybe I was just being overzealous with the !!.
There was a problem hiding this comment.
If this is happening when it should be there, you can always replaceWithErrorNode(MessageTemplate.MalformedDeclaration) if it doesn't have what it should.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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)`")) |
There was a problem hiding this comment.
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 {} | |||
There was a problem hiding this comment.
So this doesn't seem to give errors, but the cases below do.
There was a problem hiding this comment.
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 {}; |
There was a problem hiding this comment.
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.
| @@ -0,0 +1,13 @@ | |||
| // Anonymous alone was already getting through the front end | |||
| // before starting this test. | |||
| class {} | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
If this is happening when it should be there, you can always replaceWithErrorNode(MessageTemplate.MalformedDeclaration) if it doesn't have what it should.
class {}behavior (entry 0 below) isn't changed this pr: