Files
swift-mirror/test/Sema/enum_raw_representable_circularity.swift
Slava Pestov dfbb958ced Sema: Try to derive type witnesses before running inference
Sema can infer type witnesses for a small set of known conformances, to
RawRepresentable, CaseIterable, and Differentiable.

Previously, we would try to compute the type witness in this order:

1) First, via name lookup, to find an explicit nested type with the
   same name as an associated type.

2) Second, we would attempt inference.

3) Third, we would attempt derivation.

Instead, let's do 3) before 2). This avoids circularity errors in
situations where the witness can be derived, but inference fails.

This breaks source compatibility with enum declarations where the raw
type in the inheritance clause is a lie, and the user defines their
own witnesses with mismatched types. However, I suspect this does not
come up in practice, because if you don't synthesize witnesses, there
is no way to access the actual raw literal values of the enum cases.
2020-06-26 19:46:52 -04:00

14 lines
232 B
Swift

// RUN: %target-typecheck-verify-swift
// This used to fail with "reference to invalid associated type 'RawValue' of type 'E'"
_ = E(rawValue: 123)
enum E : Int {
case a = 123
init?(rawValue: RawValue) {
self = .a
}
}