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:
parent
e74723c1e7
commit
357a4a00bf
@ -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() {
|
||||
|
7
vlib/v/checker/tests/generic_eq_wrong_type.err.out
Normal file
7
vlib/v/checker/tests/generic_eq_wrong_type.err.out
Normal 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 {
|
24
vlib/v/checker/tests/generic_eq_wrong_type.err.vv
Normal file
24
vlib/v/checker/tests/generic_eq_wrong_type.err.vv
Normal 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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user