Skip to content

Commit f1e3737

Browse files
committed
Disallow adt on mixins
1 parent 3b29c70 commit f1e3737

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

modules/protocol-tests/test/src/smithy4s/api/validation/AdtTraitValidatorSpec.scala

+35
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,41 @@ import ModelUtils._
2424

2525
object AdtTraitValidatorSpec extends FunSuite {
2626

27+
test("AdtTrait - not allowed on mixins") {
28+
29+
val events = eventsWithoutLocations(
30+
assembleModel(
31+
"""$version: "2"
32+
|namespace test
33+
|
34+
|use smithy4s.meta#adt
35+
|
36+
|structure struct {
37+
| testing: String
38+
|}
39+
|
40+
|@adt
41+
|@mixin
42+
|union MyUnion {
43+
| unionMember: struct
44+
|}
45+
|""".stripMargin
46+
)
47+
)
48+
49+
val expected = ValidationEvent
50+
.builder()
51+
.id("TraitTarget")
52+
.shapeId(ShapeId.fromParts("test", "MyUnion"))
53+
.severity(Severity.ERROR)
54+
.message(
55+
"Trait `smithy4s.meta#adt` cannot be applied to `test#MyUnion`. This trait may only be applied to shapes that match the following selector: :test(union :not([trait|mixin]))"
56+
)
57+
.build()
58+
59+
assert(events.contains(expected))
60+
}
61+
2762
test("AdtTrait - return no error when union targets the structure") {
2863
assembleModel(
2964
"""$version: "2"

modules/protocol-tests/test/src/smithy4s/api/validation/ModelUtils.scala

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ private object ModelUtils {
2222
def eventsWithoutLocations(
2323
result: ValidatedResult[?]
2424
): List[ValidationEvent] = {
25+
if (!result.isBroken()) sys.error("Expected a broken result")
2526
result.getValidationEvents.asScala.toList.map(e =>
2627
e.toBuilder.sourceLocation(SourceLocation.NONE).build()
2728
)

modules/protocol/resources/META-INF/smithy/smithy4s.meta.smithy

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ string adtMember
3030
/// Implies that all members of the union are annotated with the `adtMember` trait.
3131
/// Further signals that the `sealed trait` for this adt will extend the traits
3232
/// defined by any mixins that are present on all of the adt members.
33-
@trait(selector: ":test(union, :not([trait|mixin]))")
33+
@trait(selector: ":test(union :not([trait|mixin]))")
3434
structure adt {}
3535

3636
// the indexedSeq trait can be added to list shapes in order for the generated collection

0 commit comments

Comments
 (0)