1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

ast: fix reported errors, when arrays of types defined in modules are involved (#13952)

This commit is contained in:
Vincenzo Palazzo 2022-04-08 16:38:34 +02:00 committed by GitHub
parent 2a88b313d4
commit 2d867a2766
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 0 deletions

View File

@ -1155,6 +1155,13 @@ fn (t Table) shorten_user_defined_typenames(originalname string, import_aliases
} else if res in import_aliases {
res = import_aliases[res]
} else {
// FIXME: clean this case and remove the following if
// because it is an hack to format well the type when
// there is a []modul.name
if res.contains('[]') {
idx := res.index('.') or { -1 }
return res[idx + 1..]
}
// types defined by the user
// mod.submod.submod2.Type => submod2.Type
mut parts := res.split('.')

View File

@ -0,0 +1,27 @@
vlib/v/checker/tests/check_err_msg_with_generics.vv:15:10: error: cannot cast struct `BSTree<Result<[]Token, Err<string>>>` to `int`
13 | fn test_err_msg() {
14 | typ := datatypes.BSTree<Result<[]Token, Err<string>>>{}
15 | println(int(typ))
| ~~~~~~~~
16 | }
vlib/datatypes/bstree.v:190:17: error: cannot append `T` to `[]T`
188 | }
189 | bst.in_order_traversal_helper(node.left, mut result)
190 | result << node.value
| ~~~~~
191 | bst.in_order_traversal_helper(node.right, mut result)
192 | }
vlib/datatypes/bstree.v:210:17: error: cannot append `T` to `[]T`
208 | bst.post_order_traversal_helper(node.left, mut result)
209 | bst.post_order_traversal_helper(node.right, mut result)
210 | result << node.value
| ~~~~~
211 | }
212 |
vlib/datatypes/bstree.v:226:17: error: cannot append `T` to `[]T`
224 | return
225 | }
226 | result << node.value
| ~~~~~
227 | bst.pre_order_traversal_helper(node.left, mut result)
228 | bst.pre_order_traversal_helper(node.right, mut result)

View File

@ -0,0 +1,16 @@
import datatypes
type Result<T, U> = Err<U> | Ok<T>
struct Ok<T> {
value T
}
struct Err<U> {
value U
}
fn test_err_msg() {
typ := datatypes.BSTree<Result<[]Token, Err<string>>>{}
println(int(typ))
}