disneystreaming / smithy4s

https://disneystreaming.github.io/smithy4s/
Other
351 stars 72 forks source link

ADT unions used as traits have unescaped names #1601

Closed kubukoz closed 1 month ago

kubukoz commented 2 months ago

Similar to #1592.

$version: "2"

namespace demo

@smithy4s.meta#adt
@trait
union class {
    u: Struct
}

structure Struct {}

@class(u: {

})
string MyShape
[error] ./demo/MyShape.scala:13:10
[error] an identifier expected, but 'class' found
[error]     demo.class.Struct(),
[error]          ^^^^^

This doesn't happen with normal unions.

kubukoz commented 2 months ago

I thought this was a case of CollisionAvoidance ignoring AltValueTN, but it's not. This is actually a bit more convoluted.

The problem starts in UnRef:

https://github.com/disneystreaming/smithy4s/blob/b828a134ab5452e450be88ca9790949d144ed00e/modules/codegen/src/smithy4s/codegen/internals/SmithyToIR.scala#L1238-L1242

So the problem is a result of a couple things:

I have a draft coming.

kubukoz commented 2 months ago

ok, I also discovered that using traits/defaults (typed nodes in general) from packages with keywords wouldn't go through collision avoidance. This will also be fixed in the PR.