44 lines
627 B
Text
44 lines
627 B
Text
# Pattern matching errors
|
|
struct Point
|
|
x: int,
|
|
y: int,
|
|
end
|
|
|
|
enum Result
|
|
Ok(int)
|
|
Err(string)
|
|
end
|
|
|
|
# Invalid pattern in match
|
|
fn test() -> int
|
|
match 42
|
|
x => x
|
|
end
|
|
|
|
# Missing colon in struct pattern
|
|
fn test() -> int do
|
|
let p = Point { x: 5, y: 10 }
|
|
match p
|
|
Point { x 5, y: 10 } => 1
|
|
end
|
|
end
|
|
|
|
# Invalid enum pattern
|
|
fn test() -> int do
|
|
let r = Result::Ok(42)
|
|
match r
|
|
Result::Ok value => value
|
|
end
|
|
end
|
|
|
|
# Missing pattern in match arm
|
|
fn test() -> int
|
|
match 42
|
|
=> 0
|
|
end
|
|
|
|
# Missing fat arrow in match arm
|
|
fn test() -> int
|
|
match 42
|
|
x 0
|
|
end
|