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

checker: fix generic infix expr type mismatch error (#18706)

This commit is contained in:
Turiiya 2023-06-29 20:32:21 +02:00 committed by GitHub
parent e74723c1e7
commit 357a4a00bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 0 deletions

View File

@ -743,6 +743,14 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
// Dual sides check (compatibility check)
if node.left !is ast.ComptimeCall && node.right !is ast.ComptimeCall {
if left_type.has_flag(.generic) {
left_type = c.unwrap_generic(left_type)
left_sym = c.table.sym(left_type)
}
if right_type.has_flag(.generic) {
right_type = c.unwrap_generic(right_type)
right_sym = c.table.sym(right_type)
}
if !(c.symmetric_check(left_type, right_type) && c.symmetric_check(right_type, left_type))
&& !c.pref.translated && !c.file.is_translated && !node.left.is_auto_deref_var()
&& !node.right.is_auto_deref_var() {

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/generic_eq_wrong_type.err.vv:9:13: error: infix expr: cannot use `string` (right expression) as `rune`
7 | if ztest == `\n` {
8 | println('${z}: \\n')
9 | } else if ztest == '\r' {
| ~~~~~~~~~~~~~
10 | println('${z}: \\r')
11 | } else {

View File

@ -0,0 +1,24 @@
struct Scanner[T] {
contents []T
}
pub fn (s Scanner[T]) tokenize() {
for z, ztest in s.contents {
if ztest == `\n` {
println('${z}: \\n')
} else if ztest == '\r' {
println('${z}: \\r')
} else {
println('${z}: ${ztest}')
}
}
}
pub fn new_scanner[T](contents []T) Scanner[T] {
return Scanner[T]{contents}
}
fn main() {
s := new_scanner([`\n`, `b`])
s.tokenize()
}