Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumSwiftphantom typesSingle-choice MCQ

Using a phantom type for units, this code compiles for `add` but the marked line is a compile error. What rule does the error enforce?

enum Meters {} enum Feet {} struct Length<Unit> { let value: Double } func add<U>(_ a: Length<U>, _ b: Length<U>) -> Length<U> { Length(value: a.value + b.value) } let a = Length<Meters>(value: 3) let b = Length<Feet>(value: 10) let c = add(a, b) // error here