mirror of https://github.com/smithy-lang/smithy-rs
Remove erroneous reference to the base `Symbol` when mapping Rust types (#1439)
`.addReference(this)` adds a reference to the `Symbol` on which `.mapRustType` was called. This is correct only when `f` is a function that _wraps_ its input `RustType`; for example, when `f` wraps it in a `Box` or constructs a `Vec`. However, the code is incorrect for an arbitrary `f`; for example, when `f` _swaps_ the type.
This commit is contained in:
parent
db43d7a22e
commit
1338063cdb
|
@ -101,11 +101,15 @@ fun Symbol.makeOptional(): Symbol {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Map the RustType of a symbol with [f] */
|
/**
|
||||||
|
* Map the [RustType] of a symbol with [f].
|
||||||
|
*
|
||||||
|
* WARNING: This function does not set any `SymbolReference`s on the returned symbol. You will have to add those
|
||||||
|
* yourself if your logic relies on them.
|
||||||
|
**/
|
||||||
fun Symbol.mapRustType(f: (RustType) -> RustType): Symbol {
|
fun Symbol.mapRustType(f: (RustType) -> RustType): Symbol {
|
||||||
val newType = f(this.rustType())
|
val newType = f(this.rustType())
|
||||||
return Symbol.builder().rustType(newType)
|
return Symbol.builder().rustType(newType)
|
||||||
.addReference(this)
|
|
||||||
.name(newType.name)
|
.name(newType.name)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue