Skip to content

Commit

Permalink
checker: fix missing check for alias to generic type (fix #22359) (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Oct 1, 2024
1 parent 3b9651d commit 3faf06b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) {
c.error('cannot make an alias of Result type', node.type_pos)
}
match parent_typ_sym.kind {
.placeholder, .int_literal, .float_literal {
.placeholder, .int_literal, .float_literal, .any {
c.error('unknown aliased type `${parent_typ_sym.name}`', node.type_pos)
}
.alias {
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/checker/tests/alias_to_generic_err.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
vlib/v/checker/tests/alias_to_generic_err.vv:3:12: error: unknown aliased type `T`
1 | module main
2 |
3 | type Foo = T
| ^
4 |
5 | fn main() {
6 changes: 6 additions & 0 deletions vlib/v/checker/tests/alias_to_generic_err.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module main

type Foo = T

fn main() {
}
9 changes: 8 additions & 1 deletion vlib/v/checker/tests/any_type_err.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vlib/v/checker/tests/any_type_err.vv:3:16: error: cannot use type `any` here
vlib/v/checker/tests/any_type_err.vv:3:16: error: unknown aliased type `any`
1 | // Any types should error, while parametrically polymorphic should not.
2 |
3 | type AnyType = any
Expand All @@ -19,6 +19,13 @@ vlib/v/checker/tests/any_type_err.vv:5:27: error: cannot use type `any` here
| ~~~
6 |
7 | type PolyType = T
vlib/v/checker/tests/any_type_err.vv:7:17: error: unknown aliased type `T`
5 | type AnyPolySumType = T | any
6 |
7 | type PolyType = T
| ^
8 | type PolySumType = T | string
9 |
vlib/v/checker/tests/any_type_err.vv:11:6: error: cannot use type `any` here
9 |
10 | struct AnyStructField[T] {
Expand Down

0 comments on commit 3faf06b

Please sign in to comment.