Commit e8e219a
Tao Zhuang
[NarrowedAny] Cross-spelling container reshape: full diagnostic + auto-fix-it
Implements proposal §"Containers and extensions" + decision row swiftlang#21 / swiftlang#33
for the container axis. `let xs: [String|Int] = zs` (with
`zs: [Int|String]`) now reports
error: cannot assign value of type '[Int | String]' to type '[String | Int]'
note: arguments to generic parameter 'Element' ('Int | String' and
'String | Int') are expected to be equal
fix-it: ^ as [String | Int]
with an `as` (not `as!`) fix-it, since cross-spelling reshape is a
runtime-free relabel — both sides erase to the same Any-singleton element
layout, so SIL emits a single `unchecked_addr_cast` for the coercion.
Two changes:
- `matchDeepEqualityTypes`'s NarrowedAnyType branch detects the
cross-spelling case (canonical leaf sets equal but spellings
differ) before the leaf-by-leaf Bind. When the locator path
carries an `AnyRequirement` element (e.g. `extension Array where
Element == X | Y` dispatch checking a substituted `Element` of a
different spelling), fix the same-type requirement directly via
`fixRequirementFailure` so SameTypeRequirementFailure prints the
full narrowed-Any spellings instead of the buggy `any Int` /
`any String` fallout from the previous malformed-wrap path. For
the plain conversion case, fall through to the leaf-by-leaf Bind
but tag each leaf locator with a fresh `GenericArgument` element
so `repairFailures` doesn't inherit `ExistentialConstraintType`
from the enclosing existential match (which used to construct the
malformed `ExistentialType::get(<concrete leaf>)` wrap that
defeated upstream `GenericArgumentsMismatch` recording).
- `ContextualFailure::tryTypeCoercionFixIt` recognises cross-spelling
NarrowedAnyType at container position structurally (same generic
decl, every generic arg either equal or cross-spelling-equal
NarrowedAnyType) and emits the ` as <toType>` fix-it directly,
bypassing the generic `typeCheckCheckedCast` path which would
classify it as ArrayDowncast (and suggest the wrong `as!`
direction). Restricted to the `BoundGenericType` case so the
value-level `Int|String → String|Int` path keeps using the
existing `typeCheckCheckedCast → Coercion` flow with both `as`
and `as!` fix-its preserved unchanged.
`diagnostics.swift §13` locks the full diagnostic text, the
generic-parameter-mismatch note, and the fix-it insertion. lit 13/13.1 parent 9794460 commit e8e219a
3 files changed
Lines changed: 146 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3950 | 3950 | | |
3951 | 3951 | | |
3952 | 3952 | | |
| 3953 | + | |
| 3954 | + | |
| 3955 | + | |
| 3956 | + | |
| 3957 | + | |
| 3958 | + | |
| 3959 | + | |
| 3960 | + | |
| 3961 | + | |
| 3962 | + | |
| 3963 | + | |
| 3964 | + | |
| 3965 | + | |
| 3966 | + | |
| 3967 | + | |
| 3968 | + | |
| 3969 | + | |
| 3970 | + | |
| 3971 | + | |
| 3972 | + | |
| 3973 | + | |
| 3974 | + | |
| 3975 | + | |
| 3976 | + | |
| 3977 | + | |
| 3978 | + | |
| 3979 | + | |
| 3980 | + | |
| 3981 | + | |
| 3982 | + | |
| 3983 | + | |
| 3984 | + | |
| 3985 | + | |
| 3986 | + | |
| 3987 | + | |
| 3988 | + | |
| 3989 | + | |
| 3990 | + | |
| 3991 | + | |
| 3992 | + | |
| 3993 | + | |
| 3994 | + | |
| 3995 | + | |
| 3996 | + | |
| 3997 | + | |
| 3998 | + | |
| 3999 | + | |
| 4000 | + | |
| 4001 | + | |
| 4002 | + | |
| 4003 | + | |
| 4004 | + | |
| 4005 | + | |
| 4006 | + | |
| 4007 | + | |
| 4008 | + | |
| 4009 | + | |
| 4010 | + | |
| 4011 | + | |
| 4012 | + | |
3953 | 4013 | | |
3954 | 4014 | | |
3955 | 4015 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3999 | 3999 | | |
4000 | 4000 | | |
4001 | 4001 | | |
| 4002 | + | |
| 4003 | + | |
| 4004 | + | |
| 4005 | + | |
| 4006 | + | |
| 4007 | + | |
| 4008 | + | |
| 4009 | + | |
| 4010 | + | |
| 4011 | + | |
| 4012 | + | |
| 4013 | + | |
| 4014 | + | |
| 4015 | + | |
| 4016 | + | |
| 4017 | + | |
| 4018 | + | |
| 4019 | + | |
| 4020 | + | |
| 4021 | + | |
| 4022 | + | |
| 4023 | + | |
| 4024 | + | |
| 4025 | + | |
| 4026 | + | |
| 4027 | + | |
| 4028 | + | |
| 4029 | + | |
| 4030 | + | |
| 4031 | + | |
| 4032 | + | |
| 4033 | + | |
| 4034 | + | |
| 4035 | + | |
| 4036 | + | |
| 4037 | + | |
| 4038 | + | |
| 4039 | + | |
| 4040 | + | |
| 4041 | + | |
| 4042 | + | |
| 4043 | + | |
| 4044 | + | |
| 4045 | + | |
| 4046 | + | |
| 4047 | + | |
| 4048 | + | |
| 4049 | + | |
| 4050 | + | |
| 4051 | + | |
| 4052 | + | |
| 4053 | + | |
| 4054 | + | |
| 4055 | + | |
| 4056 | + | |
| 4057 | + | |
| 4058 | + | |
| 4059 | + | |
| 4060 | + | |
| 4061 | + | |
| 4062 | + | |
| 4063 | + | |
| 4064 | + | |
| 4065 | + | |
| 4066 | + | |
| 4067 | + | |
| 4068 | + | |
| 4069 | + | |
4002 | 4070 | | |
| 4071 | + | |
| 4072 | + | |
4003 | 4073 | | |
4004 | | - | |
| 4074 | + | |
4005 | 4075 | | |
4006 | 4076 | | |
4007 | 4077 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
163 | 170 | | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
174 | 176 | | |
175 | 177 | | |
176 | | - | |
| 178 | + | |
| 179 | + | |
177 | 180 | | |
0 commit comments