checker: ensure that the variant SubType exists (#14053)
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>master
parent
48486e1afb
commit
4f14f7714f
|
@ -4197,6 +4197,12 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) ? {
|
|||
c.ensure_type_exists(info.key_type, pos) ?
|
||||
c.ensure_type_exists(info.value_type, pos) ?
|
||||
}
|
||||
.sum_type {
|
||||
info := sym.info as ast.SumType
|
||||
for concrete_typ in info.concrete_types {
|
||||
c.ensure_type_exists(concrete_typ, pos) ?
|
||||
}
|
||||
}
|
||||
else {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
vlib/v/checker/tests/undefined_type_on_sumtype.vv:1:17: error: unknown type `Token`.
|
||||
Did you mean `Ok<[]Token>`?
|
||||
1 | type ParseRes = Result<[]Token, ParseErr>
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
2 |
|
||||
3 | // Token type is unknown
|
||||
vlib/v/checker/tests/undefined_type_on_sumtype.vv:30:4: error: unused variable: `rx`
|
||||
28 | match r {
|
||||
29 | Some<ParseRes> {
|
||||
30 | rx := r.value
|
||||
| ~~
|
||||
31 | }
|
||||
32 | None<ParseRes> {}
|
|
@ -0,0 +1,34 @@
|
|||
type ParseRes = Result<[]Token, ParseErr>
|
||||
|
||||
// Token type is unknown
|
||||
//struct Token {}
|
||||
|
||||
struct ParseErr {}
|
||||
|
||||
type Opt<T> = None<T> | Some<T>
|
||||
|
||||
struct None<T> {}
|
||||
|
||||
struct Some<T> {
|
||||
value T
|
||||
}
|
||||
|
||||
type Result<T, U> = Err<U> | Ok<T>
|
||||
|
||||
struct Ok<T> {
|
||||
value T
|
||||
}
|
||||
|
||||
struct Err<U> {
|
||||
value U
|
||||
}
|
||||
|
||||
fn test_report() {
|
||||
r := Opt<ParseRes>(None<ParseRes>{})
|
||||
match r {
|
||||
Some<ParseRes> {
|
||||
rx := r.value
|
||||
}
|
||||
None<ParseRes> {}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
type ParseRes = Result<[]Token, ParseErr>
|
||||
|
||||
struct Token {}
|
||||
|
||||
struct ParseErr {}
|
||||
|
||||
type Opt<T> = None<T> | Some<T>
|
||||
|
|
Loading…
Reference in New Issue