Skip to content

Commit 3faf06b

Browse files
authored
checker: fix missing check for alias to generic type (fix #22359) (#22360)
1 parent 3b9651d commit 3faf06b

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

vlib/v/checker/checker.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) {
533533
c.error('cannot make an alias of Result type', node.type_pos)
534534
}
535535
match parent_typ_sym.kind {
536-
.placeholder, .int_literal, .float_literal {
536+
.placeholder, .int_literal, .float_literal, .any {
537537
c.error('unknown aliased type `${parent_typ_sym.name}`', node.type_pos)
538538
}
539539
.alias {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
vlib/v/checker/tests/alias_to_generic_err.vv:3:12: error: unknown aliased type `T`
2+
1 | module main
3+
2 |
4+
3 | type Foo = T
5+
| ^
6+
4 |
7+
5 | fn main() {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module main
2+
3+
type Foo = T
4+
5+
fn main() {
6+
}

vlib/v/checker/tests/any_type_err.out

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
vlib/v/checker/tests/any_type_err.vv:3:16: error: cannot use type `any` here
1+
vlib/v/checker/tests/any_type_err.vv:3:16: error: unknown aliased type `any`
22
1 | // Any types should error, while parametrically polymorphic should not.
33
2 |
44
3 | type AnyType = any
@@ -19,6 +19,13 @@ vlib/v/checker/tests/any_type_err.vv:5:27: error: cannot use type `any` here
1919
| ~~~
2020
6 |
2121
7 | type PolyType = T
22+
vlib/v/checker/tests/any_type_err.vv:7:17: error: unknown aliased type `T`
23+
5 | type AnyPolySumType = T | any
24+
6 |
25+
7 | type PolyType = T
26+
| ^
27+
8 | type PolySumType = T | string
28+
9 |
2229
vlib/v/checker/tests/any_type_err.vv:11:6: error: cannot use type `any` here
2330
9 |
2431
10 | struct AnyStructField[T] {

0 commit comments

Comments
 (0)