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

Phantom types let you tag a value at the type level without storing the tag. Given the code below, what does the compiler do with the line marked (A)?

enum Meters {} enum Feet {} struct Distance<Unit> { let value: Double } let a = Distance<Meters>(value: 10) let b = Distance<Feet>(value: 30) let c = a + b // (A) assume a generic `+` exists only for matching Unit