-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix multi-model, mixin member apply bug
On first load, via sources, there's a `DefineShape` `LoadOperation` with an `ApplyMixin` modifier. There's also a pending `@apply` statement in the `LoaderTraitMap`. When the source is assembled, that's fully resolved, the mixin is merged into the shape, then traits applied to mixed content are applied. This is a valid source model that has the trait applied to the mixed member. The import is then broken out into `LoadOperation`s to be assembled. The shape's `LoadOperations` already exist in the map and a new `DefineShape` load operation is added that also has the `ApplyMixin` modifier. The first, already fully mixed applied and built - the second, unmixed and unapplied. When we go to `applyTraitsToNonMixinsInShapeMap` on the import pass, we detect if any of the load operations that `DefineShape` contain the member where the trait is applied and add it. However, because we have **two** `LoadOperations` - one with the member and one without - we apply the trait to the shape that was already mixed and applied. We do not add it to the second `LoadOperation`, because it does not have the member. But, because we applied it somewhere, the trait is no longer unclaimed. When then later resolving the `ApplyMixin` modifier, the trait is not applied since it has been claimed elsewhere. When building the second shape and comparing it to the first, the trait is then missing, failing out due to a conflict. This is resolved by sending traits for missing members directly in to the `ApplyMixin` modifier and merging them when apply the mixin.
- Loading branch information
Showing
4 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...model/src/test/resources/software/amazon/smithy/model/loader/mixin-and-apply-model.smithy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
$version: "2.0" | ||
$operationInputSuffix: "Request" | ||
$operationOutputSuffix: "Response" | ||
|
||
namespace smithy.example | ||
|
||
@http(uri: "/machines", method: "POST") | ||
operation CreateMachine { | ||
output := { | ||
Machine: MachineData | ||
} | ||
} | ||
|
||
@mixin | ||
structure MachineDataMixin { | ||
machineId: String | ||
} | ||
|
||
structure MachineData with [MachineDataMixin] { | ||
manufacturer: String | ||
} | ||
|
||
apply MachineData$machineId @required |