From 4a25c2bb6fb9cfc3aa6ada4a337dd8903602b4bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kr=C3=BCger?= <45282134+UweKrueger@users.noreply.github.com> Date: Sun, 3 Jan 2021 23:11:09 +0100 Subject: [PATCH] types: rename `any_*`, `untyped *` -> `* literal` (#7845) --- vlib/v/ast/str.v | 2 +- vlib/v/checker/check_types.v | 2 +- vlib/v/checker/checker.v | 2 +- vlib/v/checker/tests/add_op_wrong_type_err.out | 12 ++++++------ vlib/v/checker/tests/any_int_float_ban_err.out | 2 +- .../checker/tests/array_insert_type_mismatch.out | 2 +- .../tests/array_prepend_type_mismatch.out | 2 +- .../checker/tests/bit_op_wrong_left_type_err.out | 2 +- .../tests/bit_op_wrong_right_type_err.out | 2 +- vlib/v/checker/tests/cannot_cast_to_alias.out | 2 +- vlib/v/checker/tests/cannot_cast_to_struct.out | 2 +- vlib/v/checker/tests/cast_string_err.out | 2 +- vlib/v/checker/tests/div_op_wrong_type_err.out | 12 ++++++------ vlib/v/checker/tests/fn_var.out | 2 +- vlib/v/checker/tests/for_in_index_type.out | 2 +- .../checker/tests/function_wrong_return_type.out | 2 +- vlib/v/checker/tests/if_expr_mismatch.out | 2 +- vlib/v/checker/tests/in_mismatch_type.out | 10 +++++----- vlib/v/checker/tests/is_type_not_exist.out | 2 +- vlib/v/checker/tests/match_undefined_cond.out | 4 ++-- vlib/v/checker/tests/minus_op_wrong_type_err.out | 12 ++++++------ vlib/v/checker/tests/mod_op_wrong_type_err.out | 12 ++++++------ vlib/v/checker/tests/mul_op_wrong_type_err.out | 16 ++++++++-------- ..._block_returns_value_of_incompatible_type.out | 2 +- vlib/v/checker/tests/ptr_assign.out | 2 +- vlib/v/checker/tests/return_type.out | 2 +- .../tests/rshift_op_wrong_left_type_err.out | 2 +- .../tests/rshift_op_wrong_right_type_err.out | 2 +- .../tests/shift_op_wrong_left_type_err.out | 2 +- .../tests/shift_op_wrong_right_type_err.out | 2 +- .../tests/fn_type_only_args_in_interfaces.out | 0 vlib/v/table/types.v | 13 +++++++++++-- 32 files changed, 73 insertions(+), 64 deletions(-) mode change 100755 => 100644 vlib/v/parser/tests/fn_type_only_args_in_interfaces.out diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index d85bf79a34..f75cd0e1d7 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -26,7 +26,7 @@ pub fn (node &FnDecl) stringify(t &table.Table, cur_mod string, m2a map[string]s } mut receiver := '' if node.is_method { - mut styp := util.no_cur_mod(t.type_to_str(node.receiver.typ), cur_mod) + mut styp := util.no_cur_mod(t.type_to_code(node.receiver.typ), cur_mod) m := if node.rec_mut { node.receiver.typ.share().str() + ' ' } else { '' } if node.rec_mut { styp = styp[1..] // remove & diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index 3bca0fb59a..7b0ab45d98 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -178,7 +178,7 @@ fn (mut c Checker) check_shift(left_type table.Type, right_type table.Type, left c.error('invalid operation: shift of type `$sym.name`', left_pos) return table.void_type } else if !right_type.is_int() { - c.error('cannot shift non-integer type ${c.table.get_type_symbol(right_type).name} into type ${c.table.get_type_symbol(left_type).name}', + c.error('cannot shift non-integer type `${c.table.get_type_symbol(right_type).name}` into type `${c.table.get_type_symbol(left_type).name}`', right_pos) return table.void_type } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 0c6647fa76..ded686f710 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -807,7 +807,7 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type { c.error('float modulo not allowed, use math.fmod() instead', pos) } else { - c.error('$side type of `$infix_expr.op.str()` cannot be non-integer type $name', + c.error('$side type of `$infix_expr.op.str()` cannot be non-integer type `$name`', pos) } } diff --git a/vlib/v/checker/tests/add_op_wrong_type_err.out b/vlib/v/checker/tests/add_op_wrong_type_err.out index 1cc9c857e3..b87de4dd62 100644 --- a/vlib/v/checker/tests/add_op_wrong_type_err.out +++ b/vlib/v/checker/tests/add_op_wrong_type_err.out @@ -1,39 +1,39 @@ -vlib/v/checker/tests/add_op_wrong_type_err.vv:3:13: error: mismatched types `Aaa` and `untyped int` +vlib/v/checker/tests/add_op_wrong_type_err.vv:3:13: error: mismatched types `Aaa` and `int literal` 1 | struct Aaa{} 2 | fn main() { 3 | println(Aaa{} + 10) | ~~~~~ 4 | println(10 + Aaa{}) 5 | println([1,2,3] + 10) -vlib/v/checker/tests/add_op_wrong_type_err.vv:4:18: error: mismatched types `untyped int` and `Aaa` +vlib/v/checker/tests/add_op_wrong_type_err.vv:4:18: error: mismatched types `int literal` and `Aaa` 2 | fn main() { 3 | println(Aaa{} + 10) 4 | println(10 + Aaa{}) | ~~~~~ 5 | println([1,2,3] + 10) 6 | println(10 + [1,2,3]) -vlib/v/checker/tests/add_op_wrong_type_err.vv:5:13: error: mismatched types `[]int` and `untyped int` +vlib/v/checker/tests/add_op_wrong_type_err.vv:5:13: error: mismatched types `[]int` and `int literal` 3 | println(Aaa{} + 10) 4 | println(10 + Aaa{}) 5 | println([1,2,3] + 10) | ~~~~~~~ 6 | println(10 + [1,2,3]) 7 | a := map[string]int -vlib/v/checker/tests/add_op_wrong_type_err.vv:6:18: error: mismatched types `untyped int` and `[]int` +vlib/v/checker/tests/add_op_wrong_type_err.vv:6:18: error: mismatched types `int literal` and `[]int` 4 | println(10 + Aaa{}) 5 | println([1,2,3] + 10) 6 | println(10 + [1,2,3]) | ~~~~~~~ 7 | a := map[string]int 8 | println(a + 10) -vlib/v/checker/tests/add_op_wrong_type_err.vv:8:13: error: mismatched types `map[string]int` and `untyped int` +vlib/v/checker/tests/add_op_wrong_type_err.vv:8:13: error: mismatched types `map[string]int` and `int literal` 6 | println(10 + [1,2,3]) 7 | a := map[string]int 8 | println(a + 10) | ^ 9 | println(10 + a) 10 | } -vlib/v/checker/tests/add_op_wrong_type_err.vv:9:18: error: mismatched types `untyped int` and `map[string]int` +vlib/v/checker/tests/add_op_wrong_type_err.vv:9:18: error: mismatched types `int literal` and `map[string]int` 7 | a := map[string]int 8 | println(a + 10) 9 | println(10 + a) diff --git a/vlib/v/checker/tests/any_int_float_ban_err.out b/vlib/v/checker/tests/any_int_float_ban_err.out index 624f2ef83b..023506ff49 100644 --- a/vlib/v/checker/tests/any_int_float_ban_err.out +++ b/vlib/v/checker/tests/any_int_float_ban_err.out @@ -39,7 +39,7 @@ vlib/v/checker/tests/any_int_float_ban_err.vv:13:1: error: unknown type `any_int | ~~~~~~~~~~~~~~~~~ 14 | return 1 15 | } -vlib/v/checker/tests/any_int_float_ban_err.vv:14:12: error: cannot use `untyped int` as type `any_int` in return argument +vlib/v/checker/tests/any_int_float_ban_err.vv:14:12: error: cannot use `int literal` as type `any_int` in return argument 12 | 13 | fn foo2() any_int { 14 | return 1 diff --git a/vlib/v/checker/tests/array_insert_type_mismatch.out b/vlib/v/checker/tests/array_insert_type_mismatch.out index 59a694a33c..78f0a649fb 100644 --- a/vlib/v/checker/tests/array_insert_type_mismatch.out +++ b/vlib/v/checker/tests/array_insert_type_mismatch.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/array_insert_type_mismatch.vv:3:14: error: cannot insert `untyped float` to `[]int` +vlib/v/checker/tests/array_insert_type_mismatch.vv:3:14: error: cannot insert `float literal` to `[]int` 1 | fn main() { 2 | mut a := [1, 2] 3 | a.insert(1, 2.3) diff --git a/vlib/v/checker/tests/array_prepend_type_mismatch.out b/vlib/v/checker/tests/array_prepend_type_mismatch.out index f711eaaa4e..8e74b7f08a 100644 --- a/vlib/v/checker/tests/array_prepend_type_mismatch.out +++ b/vlib/v/checker/tests/array_prepend_type_mismatch.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/array_prepend_type_mismatch.vv:3:12: error: cannot prepend `untyped float` to `[]int` +vlib/v/checker/tests/array_prepend_type_mismatch.vv:3:12: error: cannot prepend `float literal` to `[]int` 1 | fn main() { 2 | mut a := [1, 2] 3 | a.prepend(2.3) diff --git a/vlib/v/checker/tests/bit_op_wrong_left_type_err.out b/vlib/v/checker/tests/bit_op_wrong_left_type_err.out index 1c327322b8..e8d7a31d9f 100644 --- a/vlib/v/checker/tests/bit_op_wrong_left_type_err.out +++ b/vlib/v/checker/tests/bit_op_wrong_left_type_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/bit_op_wrong_left_type_err.vv:2:10: error: left type of `&` cannot be non-integer type untyped float +vlib/v/checker/tests/bit_op_wrong_left_type_err.vv:2:10: error: left type of `&` cannot be non-integer type `float literal` 1 | fn main() { 2 | println(0.5 & 1) | ~~~ diff --git a/vlib/v/checker/tests/bit_op_wrong_right_type_err.out b/vlib/v/checker/tests/bit_op_wrong_right_type_err.out index be0a7f0667..7b24344954 100644 --- a/vlib/v/checker/tests/bit_op_wrong_right_type_err.out +++ b/vlib/v/checker/tests/bit_op_wrong_right_type_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/bit_op_wrong_right_type_err.vv:2:14: error: right type of `|` cannot be non-integer type untyped float +vlib/v/checker/tests/bit_op_wrong_right_type_err.vv:2:14: error: right type of `|` cannot be non-integer type `float literal` 1 | fn main() { 2 | println(1 | 0.5) | ~~~ diff --git a/vlib/v/checker/tests/cannot_cast_to_alias.out b/vlib/v/checker/tests/cannot_cast_to_alias.out index 82457910f9..6a7960cf4c 100644 --- a/vlib/v/checker/tests/cannot_cast_to_alias.out +++ b/vlib/v/checker/tests/cannot_cast_to_alias.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/cannot_cast_to_alias.vv:6:7: error: cannot convert type `untyped int` to `MyType` (alias to `string`) +vlib/v/checker/tests/cannot_cast_to_alias.vv:6:7: error: cannot convert type `int literal` to `MyType` (alias to `string`) 4 | 5 | fn main() { 6 | _ := MyType(5) diff --git a/vlib/v/checker/tests/cannot_cast_to_struct.out b/vlib/v/checker/tests/cannot_cast_to_struct.out index d4e05f75a3..a9c103caf2 100644 --- a/vlib/v/checker/tests/cannot_cast_to_struct.out +++ b/vlib/v/checker/tests/cannot_cast_to_struct.out @@ -12,7 +12,7 @@ vlib/v/checker/tests/cannot_cast_to_struct.vv:12:6: error: cannot cast `Alphabet | ~~~~~~~~ 13 | _ = Xyz(5) 14 | s := Abc{} -vlib/v/checker/tests/cannot_cast_to_struct.vv:13:6: error: cannot cast `untyped int` to struct +vlib/v/checker/tests/cannot_cast_to_struct.vv:13:6: error: cannot cast `int literal` to struct 11 | sum := Alphabet(Xyz{}) 12 | _ = Xyz(sum) 13 | _ = Xyz(5) diff --git a/vlib/v/checker/tests/cast_string_err.out b/vlib/v/checker/tests/cast_string_err.out index 73af881be9..3c09bf4811 100644 --- a/vlib/v/checker/tests/cast_string_err.out +++ b/vlib/v/checker/tests/cast_string_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/cast_string_err.vv:2:7: error: cannot cast type `untyped int` to string, use `x.str()` instead +vlib/v/checker/tests/cast_string_err.vv:2:7: error: cannot cast type `int literal` to string, use `x.str()` instead 1 | fn main() { 2 | a := string(1) | ~~~~~~~~~ diff --git a/vlib/v/checker/tests/div_op_wrong_type_err.out b/vlib/v/checker/tests/div_op_wrong_type_err.out index 4e1356b916..328114a939 100644 --- a/vlib/v/checker/tests/div_op_wrong_type_err.out +++ b/vlib/v/checker/tests/div_op_wrong_type_err.out @@ -1,39 +1,39 @@ -vlib/v/checker/tests/div_op_wrong_type_err.vv:3:13: error: mismatched types `Aaa` and `untyped int` +vlib/v/checker/tests/div_op_wrong_type_err.vv:3:13: error: mismatched types `Aaa` and `int literal` 1 | struct Aaa{} 2 | fn main() { 3 | println(Aaa{} / 10) | ~~~~~ 4 | println(10 / Aaa{}) 5 | println([1,2,3] / 10) -vlib/v/checker/tests/div_op_wrong_type_err.vv:4:18: error: mismatched types `untyped int` and `Aaa` +vlib/v/checker/tests/div_op_wrong_type_err.vv:4:18: error: mismatched types `int literal` and `Aaa` 2 | fn main() { 3 | println(Aaa{} / 10) 4 | println(10 / Aaa{}) | ~~~~~ 5 | println([1,2,3] / 10) 6 | println(10 / [1,2,3]) -vlib/v/checker/tests/div_op_wrong_type_err.vv:5:13: error: mismatched types `[]int` and `untyped int` +vlib/v/checker/tests/div_op_wrong_type_err.vv:5:13: error: mismatched types `[]int` and `int literal` 3 | println(Aaa{} / 10) 4 | println(10 / Aaa{}) 5 | println([1,2,3] / 10) | ~~~~~~~ 6 | println(10 / [1,2,3]) 7 | a := map[string]int -vlib/v/checker/tests/div_op_wrong_type_err.vv:6:18: error: mismatched types `untyped int` and `[]int` +vlib/v/checker/tests/div_op_wrong_type_err.vv:6:18: error: mismatched types `int literal` and `[]int` 4 | println(10 / Aaa{}) 5 | println([1,2,3] / 10) 6 | println(10 / [1,2,3]) | ~~~~~~~ 7 | a := map[string]int 8 | println(a / 10) -vlib/v/checker/tests/div_op_wrong_type_err.vv:8:13: error: mismatched types `map[string]int` and `untyped int` +vlib/v/checker/tests/div_op_wrong_type_err.vv:8:13: error: mismatched types `map[string]int` and `int literal` 6 | println(10 / [1,2,3]) 7 | a := map[string]int 8 | println(a / 10) | ^ 9 | println(10 / a) 10 | } -vlib/v/checker/tests/div_op_wrong_type_err.vv:9:18: error: mismatched types `untyped int` and `map[string]int` +vlib/v/checker/tests/div_op_wrong_type_err.vv:9:18: error: mismatched types `int literal` and `map[string]int` 7 | a := map[string]int 8 | println(a / 10) 9 | println(10 / a) diff --git a/vlib/v/checker/tests/fn_var.out b/vlib/v/checker/tests/fn_var.out index ef231cfaad..b65af8fa0c 100644 --- a/vlib/v/checker/tests/fn_var.out +++ b/vlib/v/checker/tests/fn_var.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/fn_var.vv:2:5: error: cannot assign to `f`: expected `fn (int) byte`, not `untyped int` +vlib/v/checker/tests/fn_var.vv:2:5: error: cannot assign to `f`: expected `fn (int) byte`, not `int literal` 1 | mut f := fn(i int) byte {} 2 | f = 4 | ^ diff --git a/vlib/v/checker/tests/for_in_index_type.out b/vlib/v/checker/tests/for_in_index_type.out index 29818b9d84..8d577390e0 100644 --- a/vlib/v/checker/tests/for_in_index_type.out +++ b/vlib/v/checker/tests/for_in_index_type.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/for_in_index_type.vv:2:11: error: for in: cannot index `untyped int` +vlib/v/checker/tests/for_in_index_type.vv:2:11: error: for in: cannot index `int literal` 1 | fn main() { 2 | for a in 52 { | ~~ diff --git a/vlib/v/checker/tests/function_wrong_return_type.out b/vlib/v/checker/tests/function_wrong_return_type.out index e416357188..070d573fd1 100644 --- a/vlib/v/checker/tests/function_wrong_return_type.out +++ b/vlib/v/checker/tests/function_wrong_return_type.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/function_wrong_return_type.vv:2:9: error: cannot use `untyped float` as type `int` in return argument +vlib/v/checker/tests/function_wrong_return_type.vv:2:9: error: cannot use `float literal` as type `int` in return argument 1 | fn h() int { 2 | return 3.14 | ~~~~ diff --git a/vlib/v/checker/tests/if_expr_mismatch.out b/vlib/v/checker/tests/if_expr_mismatch.out index 99835d662a..0c45b88830 100644 --- a/vlib/v/checker/tests/if_expr_mismatch.out +++ b/vlib/v/checker/tests/if_expr_mismatch.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/if_expr_mismatch.vv:2:7: error: mismatched types `string` and `untyped int` +vlib/v/checker/tests/if_expr_mismatch.vv:2:7: error: mismatched types `string` and `int literal` 1 | fn main() { 2 | s := if true { '12' } else { 12 } | ~~ diff --git a/vlib/v/checker/tests/in_mismatch_type.out b/vlib/v/checker/tests/in_mismatch_type.out index 651968a02e..b174c0f574 100644 --- a/vlib/v/checker/tests/in_mismatch_type.out +++ b/vlib/v/checker/tests/in_mismatch_type.out @@ -1,18 +1,18 @@ -vlib/v/checker/tests/in_mismatch_type.vv:10:7: error: left operand to `in` does not match the array element type: expected `string`, not `untyped int` +vlib/v/checker/tests/in_mismatch_type.vv:10:7: error: left operand to `in` does not match the array element type: expected `string`, not `int literal` 8 | } 9 | s := 'abcd' 10 | if 1 in a_s { | ~~ 11 | println('ok') 12 | } -vlib/v/checker/tests/in_mismatch_type.vv:13:7: error: left operand to `in` does not match the map key type: expected `string`, not `untyped int` +vlib/v/checker/tests/in_mismatch_type.vv:13:7: error: left operand to `in` does not match the map key type: expected `string`, not `int literal` 11 | println('ok') 12 | } 13 | if 2 in m { | ~~ 14 | println('yeah') 15 | } -vlib/v/checker/tests/in_mismatch_type.vv:16:7: error: left operand to `in` does not match: expected `string`, not `untyped int` +vlib/v/checker/tests/in_mismatch_type.vv:16:7: error: left operand to `in` does not match: expected `string`, not `int literal` 14 | println('yeah') 15 | } 16 | if 3 in s { @@ -54,7 +54,7 @@ vlib/v/checker/tests/in_mismatch_type.vv:31:9: error: left operand to `in` does | ~~ 32 | println('all right') 33 | } -vlib/v/checker/tests/in_mismatch_type.vv:34:7: error: left operand to `!in` does not match the array element type: expected `string`, not `untyped int` +vlib/v/checker/tests/in_mismatch_type.vv:34:7: error: left operand to `!in` does not match the array element type: expected `string`, not `int literal` 32 | println('all right') 33 | } 34 | if 1 !in a_s { @@ -68,7 +68,7 @@ vlib/v/checker/tests/in_mismatch_type.vv:37:9: error: left operand to `!in` does | ~~~ 38 | println('good') 39 | } -vlib/v/checker/tests/in_mismatch_type.vv:41:7: error: left operand to `!in` does not match the map key type: expected `string`, not `untyped int` +vlib/v/checker/tests/in_mismatch_type.vv:41:7: error: left operand to `!in` does not match the map key type: expected `string`, not `int literal` 39 | } 40 | 41 | if 5 !in m { diff --git a/vlib/v/checker/tests/is_type_not_exist.out b/vlib/v/checker/tests/is_type_not_exist.out index a7eed5ce06..881050431a 100644 --- a/vlib/v/checker/tests/is_type_not_exist.out +++ b/vlib/v/checker/tests/is_type_not_exist.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/is_type_not_exist.vv:4:25: error: cannot use `untyped int` as `Integer` in argument 1 to `fn_with_sum_type_param` +vlib/v/checker/tests/is_type_not_exist.vv:4:25: error: cannot use `int literal` as `Integer` in argument 1 to `fn_with_sum_type_param` 2 | 3 | fn main() { 4 | fn_with_sum_type_param(1) diff --git a/vlib/v/checker/tests/match_undefined_cond.out b/vlib/v/checker/tests/match_undefined_cond.out index be30923f7c..ca813c40ce 100644 --- a/vlib/v/checker/tests/match_undefined_cond.out +++ b/vlib/v/checker/tests/match_undefined_cond.out @@ -5,14 +5,14 @@ vlib/v/checker/tests/match_undefined_cond.vv:4:15: error: undefined ident: `Asd` | ~~~ 5 | 1 { 'foo' } 6 | 2 { 'test' } -vlib/v/checker/tests/match_undefined_cond.vv:5:3: error: cannot match `untyped int` with `void` condition +vlib/v/checker/tests/match_undefined_cond.vv:5:3: error: cannot match `int literal` with `void` condition 3 | fn main() { 4 | res := match Asd { 5 | 1 { 'foo' } | ^ 6 | 2 { 'test' } 7 | else { '' } -vlib/v/checker/tests/match_undefined_cond.vv:6:3: error: cannot match `untyped int` with `void` condition +vlib/v/checker/tests/match_undefined_cond.vv:6:3: error: cannot match `int literal` with `void` condition 4 | res := match Asd { 5 | 1 { 'foo' } 6 | 2 { 'test' } diff --git a/vlib/v/checker/tests/minus_op_wrong_type_err.out b/vlib/v/checker/tests/minus_op_wrong_type_err.out index b255d8d76d..b51dfbd6c6 100644 --- a/vlib/v/checker/tests/minus_op_wrong_type_err.out +++ b/vlib/v/checker/tests/minus_op_wrong_type_err.out @@ -1,39 +1,39 @@ -vlib/v/checker/tests/minus_op_wrong_type_err.vv:3:13: error: mismatched types `Aaa` and `untyped int` +vlib/v/checker/tests/minus_op_wrong_type_err.vv:3:13: error: mismatched types `Aaa` and `int literal` 1 | struct Aaa{} 2 | fn main() { 3 | println(Aaa{} - 10) | ~~~~~ 4 | println(10 - Aaa{}) 5 | println([1,2,3] - 10) -vlib/v/checker/tests/minus_op_wrong_type_err.vv:4:18: error: mismatched types `untyped int` and `Aaa` +vlib/v/checker/tests/minus_op_wrong_type_err.vv:4:18: error: mismatched types `int literal` and `Aaa` 2 | fn main() { 3 | println(Aaa{} - 10) 4 | println(10 - Aaa{}) | ~~~~~ 5 | println([1,2,3] - 10) 6 | println(10 - [1,2,3]) -vlib/v/checker/tests/minus_op_wrong_type_err.vv:5:13: error: mismatched types `[]int` and `untyped int` +vlib/v/checker/tests/minus_op_wrong_type_err.vv:5:13: error: mismatched types `[]int` and `int literal` 3 | println(Aaa{} - 10) 4 | println(10 - Aaa{}) 5 | println([1,2,3] - 10) | ~~~~~~~ 6 | println(10 - [1,2,3]) 7 | a := map[string]int -vlib/v/checker/tests/minus_op_wrong_type_err.vv:6:18: error: mismatched types `untyped int` and `[]int` +vlib/v/checker/tests/minus_op_wrong_type_err.vv:6:18: error: mismatched types `int literal` and `[]int` 4 | println(10 - Aaa{}) 5 | println([1,2,3] - 10) 6 | println(10 - [1,2,3]) | ~~~~~~~ 7 | a := map[string]int 8 | println(a - 10) -vlib/v/checker/tests/minus_op_wrong_type_err.vv:8:13: error: mismatched types `map[string]int` and `untyped int` +vlib/v/checker/tests/minus_op_wrong_type_err.vv:8:13: error: mismatched types `map[string]int` and `int literal` 6 | println(10 - [1,2,3]) 7 | a := map[string]int 8 | println(a - 10) | ^ 9 | println(10 - a) 10 | } -vlib/v/checker/tests/minus_op_wrong_type_err.vv:9:18: error: mismatched types `untyped int` and `map[string]int` +vlib/v/checker/tests/minus_op_wrong_type_err.vv:9:18: error: mismatched types `int literal` and `map[string]int` 7 | a := map[string]int 8 | println(a - 10) 9 | println(10 - a) diff --git a/vlib/v/checker/tests/mod_op_wrong_type_err.out b/vlib/v/checker/tests/mod_op_wrong_type_err.out index 8c8d9ed630..04285320cc 100644 --- a/vlib/v/checker/tests/mod_op_wrong_type_err.out +++ b/vlib/v/checker/tests/mod_op_wrong_type_err.out @@ -12,42 +12,42 @@ vlib/v/checker/tests/mod_op_wrong_type_err.vv:4:14: error: float modulo not allo | ~~~ 5 | println([1,2,3] % 1) 6 | println(1 % [1,2,3]) -vlib/v/checker/tests/mod_op_wrong_type_err.vv:5:10: error: mismatched types `[]int` and `untyped int` +vlib/v/checker/tests/mod_op_wrong_type_err.vv:5:10: error: mismatched types `[]int` and `int literal` 3 | println(0.5 % 1) 4 | println(1 % 0.5) 5 | println([1,2,3] % 1) | ~~~~~~~ 6 | println(1 % [1,2,3]) 7 | a := Aaa{} -vlib/v/checker/tests/mod_op_wrong_type_err.vv:6:14: error: mismatched types `untyped int` and `[]int` +vlib/v/checker/tests/mod_op_wrong_type_err.vv:6:14: error: mismatched types `int literal` and `[]int` 4 | println(1 % 0.5) 5 | println([1,2,3] % 1) 6 | println(1 % [1,2,3]) | ~~~~~~~ 7 | a := Aaa{} 8 | println(a % 1) -vlib/v/checker/tests/mod_op_wrong_type_err.vv:8:10: error: mismatched types `Aaa` and `untyped int` +vlib/v/checker/tests/mod_op_wrong_type_err.vv:8:10: error: mismatched types `Aaa` and `int literal` 6 | println(1 % [1,2,3]) 7 | a := Aaa{} 8 | println(a % 1) | ^ 9 | println(1 % a) 10 | b := map[string]int -vlib/v/checker/tests/mod_op_wrong_type_err.vv:9:14: error: mismatched types `untyped int` and `Aaa` +vlib/v/checker/tests/mod_op_wrong_type_err.vv:9:14: error: mismatched types `int literal` and `Aaa` 7 | a := Aaa{} 8 | println(a % 1) 9 | println(1 % a) | ^ 10 | b := map[string]int 11 | println(b % 1) -vlib/v/checker/tests/mod_op_wrong_type_err.vv:11:10: error: mismatched types `map[string]int` and `untyped int` +vlib/v/checker/tests/mod_op_wrong_type_err.vv:11:10: error: mismatched types `map[string]int` and `int literal` 9 | println(1 % a) 10 | b := map[string]int 11 | println(b % 1) | ^ 12 | println(1 % b) 13 | } -vlib/v/checker/tests/mod_op_wrong_type_err.vv:12:14: error: mismatched types `untyped int` and `map[string]int` +vlib/v/checker/tests/mod_op_wrong_type_err.vv:12:14: error: mismatched types `int literal` and `map[string]int` 10 | b := map[string]int 11 | println(b % 1) 12 | println(1 % b) diff --git a/vlib/v/checker/tests/mul_op_wrong_type_err.out b/vlib/v/checker/tests/mul_op_wrong_type_err.out index 654e9e9bcc..6d6c714a55 100644 --- a/vlib/v/checker/tests/mul_op_wrong_type_err.out +++ b/vlib/v/checker/tests/mul_op_wrong_type_err.out @@ -1,53 +1,53 @@ -vlib/v/checker/tests/mul_op_wrong_type_err.vv:5:13: error: mismatched types `Aaa` and `untyped int` +vlib/v/checker/tests/mul_op_wrong_type_err.vv:5:13: error: mismatched types `Aaa` and `int literal` 3 | struct Aaa{} 4 | fn main() { 5 | println(Aaa{} * 10) | ~~~~~ 6 | println(10 * Aaa{}) 7 | println([1,2,3] * 10) -vlib/v/checker/tests/mul_op_wrong_type_err.vv:6:18: error: mismatched types `untyped int` and `Aaa` +vlib/v/checker/tests/mul_op_wrong_type_err.vv:6:18: error: mismatched types `int literal` and `Aaa` 4 | fn main() { 5 | println(Aaa{} * 10) 6 | println(10 * Aaa{}) | ~~~~~ 7 | println([1,2,3] * 10) 8 | println(10 * [1,2,3]) -vlib/v/checker/tests/mul_op_wrong_type_err.vv:7:13: error: mismatched types `[]int` and `untyped int` +vlib/v/checker/tests/mul_op_wrong_type_err.vv:7:13: error: mismatched types `[]int` and `int literal` 5 | println(Aaa{} * 10) 6 | println(10 * Aaa{}) 7 | println([1,2,3] * 10) | ~~~~~~~ 8 | println(10 * [1,2,3]) 9 | a := map[string]int -vlib/v/checker/tests/mul_op_wrong_type_err.vv:8:18: error: mismatched types `untyped int` and `[]int` +vlib/v/checker/tests/mul_op_wrong_type_err.vv:8:18: error: mismatched types `int literal` and `[]int` 6 | println(10 * Aaa{}) 7 | println([1,2,3] * 10) 8 | println(10 * [1,2,3]) | ~~~~~~~ 9 | a := map[string]int 10 | println(a * 10) -vlib/v/checker/tests/mul_op_wrong_type_err.vv:10:13: error: mismatched types `map[string]int` and `untyped int` +vlib/v/checker/tests/mul_op_wrong_type_err.vv:10:13: error: mismatched types `map[string]int` and `int literal` 8 | println(10 * [1,2,3]) 9 | a := map[string]int 10 | println(a * 10) | ^ 11 | println(10 * a) 12 | c1 := cmplx.complex(1,-2) -vlib/v/checker/tests/mul_op_wrong_type_err.vv:11:18: error: mismatched types `untyped int` and `map[string]int` +vlib/v/checker/tests/mul_op_wrong_type_err.vv:11:18: error: mismatched types `int literal` and `map[string]int` 9 | a := map[string]int 10 | println(a * 10) 11 | println(10 * a) | ^ 12 | c1 := cmplx.complex(1,-2) 13 | c2 := c1 * 2.0 -vlib/v/checker/tests/mul_op_wrong_type_err.vv:13:11: error: infix expr: cannot use `untyped float` (right expression) as `math.complex.Complex` +vlib/v/checker/tests/mul_op_wrong_type_err.vv:13:11: error: infix expr: cannot use `float literal` (right expression) as `math.complex.Complex` 11 | println(10 * a) 12 | c1 := cmplx.complex(1,-2) 13 | c2 := c1 * 2.0 | ^ 14 | println(c2) 15 | c3 := 2.0 * c1 -vlib/v/checker/tests/mul_op_wrong_type_err.vv:15:12: error: infix expr: cannot use `math.complex.Complex` (right expression) as `untyped float` +vlib/v/checker/tests/mul_op_wrong_type_err.vv:15:12: error: infix expr: cannot use `math.complex.Complex` (right expression) as `float literal` 13 | c2 := c1 * 2.0 14 | println(c2) 15 | c3 := 2.0 * c1 diff --git a/vlib/v/checker/tests/optional_or_block_returns_value_of_incompatible_type.out b/vlib/v/checker/tests/optional_or_block_returns_value_of_incompatible_type.out index 0c71a32091..0cd1b389a1 100644 --- a/vlib/v/checker/tests/optional_or_block_returns_value_of_incompatible_type.out +++ b/vlib/v/checker/tests/optional_or_block_returns_value_of_incompatible_type.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/optional_or_block_returns_value_of_incompatible_type.vv:13:3: error: the default expression type in the `or` block should be `string`, instead you gave a value of type `untyped int` +vlib/v/checker/tests/optional_or_block_returns_value_of_incompatible_type.vv:13:3: error: the default expression type in the `or` block should be `string`, instead you gave a value of type `int literal` 11 | // must be of the same type of the return 12 | // type of the `test_optional` function 13 | 123 diff --git a/vlib/v/checker/tests/ptr_assign.out b/vlib/v/checker/tests/ptr_assign.out index 4f1a66c744..f4de352c22 100644 --- a/vlib/v/checker/tests/ptr_assign.out +++ b/vlib/v/checker/tests/ptr_assign.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/ptr_assign.vv:3:5: error: cannot assign to `p`: expected `&int`, not `untyped int` +vlib/v/checker/tests/ptr_assign.vv:3:5: error: cannot assign to `p`: expected `&int`, not `int literal` 1 | mut v := 43 2 | mut p := &v 3 | p = 4 diff --git a/vlib/v/checker/tests/return_type.out b/vlib/v/checker/tests/return_type.out index 9f142478c1..971347c65e 100644 --- a/vlib/v/checker/tests/return_type.out +++ b/vlib/v/checker/tests/return_type.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/return_type.vv:2:9: error: cannot use `untyped int` as type `bool` in return argument +vlib/v/checker/tests/return_type.vv:2:9: error: cannot use `int literal` as type `bool` in return argument 1 | fn test() bool { 2 | return 100 | ~~~ diff --git a/vlib/v/checker/tests/rshift_op_wrong_left_type_err.out b/vlib/v/checker/tests/rshift_op_wrong_left_type_err.out index ad860c209d..35daa5f408 100644 --- a/vlib/v/checker/tests/rshift_op_wrong_left_type_err.out +++ b/vlib/v/checker/tests/rshift_op_wrong_left_type_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/rshift_op_wrong_left_type_err.vv:2:10: error: invalid operation: shift of type `untyped float` +vlib/v/checker/tests/rshift_op_wrong_left_type_err.vv:2:10: error: invalid operation: shift of type `float literal` 1 | fn main() { 2 | println(0.5 >> 1) | ~~~ diff --git a/vlib/v/checker/tests/rshift_op_wrong_right_type_err.out b/vlib/v/checker/tests/rshift_op_wrong_right_type_err.out index e99ae9b708..7a0c5d9b86 100644 --- a/vlib/v/checker/tests/rshift_op_wrong_right_type_err.out +++ b/vlib/v/checker/tests/rshift_op_wrong_right_type_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/rshift_op_wrong_right_type_err.vv:2:15: error: cannot shift non-integer type untyped float into type untyped int +vlib/v/checker/tests/rshift_op_wrong_right_type_err.vv:2:15: error: cannot shift non-integer type `float literal` into type `int literal` 1 | fn main() { 2 | println(1 >> 0.5) | ~~~ diff --git a/vlib/v/checker/tests/shift_op_wrong_left_type_err.out b/vlib/v/checker/tests/shift_op_wrong_left_type_err.out index bee4383253..f9dcdf76f6 100644 --- a/vlib/v/checker/tests/shift_op_wrong_left_type_err.out +++ b/vlib/v/checker/tests/shift_op_wrong_left_type_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/shift_op_wrong_left_type_err.vv:2:10: error: invalid operation: shift of type `untyped float` +vlib/v/checker/tests/shift_op_wrong_left_type_err.vv:2:10: error: invalid operation: shift of type `float literal` 1 | fn main() { 2 | println(0.5 << 1) | ~~~ diff --git a/vlib/v/checker/tests/shift_op_wrong_right_type_err.out b/vlib/v/checker/tests/shift_op_wrong_right_type_err.out index 91175b4675..87d0a44972 100644 --- a/vlib/v/checker/tests/shift_op_wrong_right_type_err.out +++ b/vlib/v/checker/tests/shift_op_wrong_right_type_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/shift_op_wrong_right_type_err.vv:2:15: error: cannot shift non-integer type untyped float into type untyped int +vlib/v/checker/tests/shift_op_wrong_right_type_err.vv:2:15: error: cannot shift non-integer type `float literal` into type `int literal` 1 | fn main() { 2 | println(1 << 0.5) | ~~~ diff --git a/vlib/v/parser/tests/fn_type_only_args_in_interfaces.out b/vlib/v/parser/tests/fn_type_only_args_in_interfaces.out old mode 100755 new mode 100644 diff --git a/vlib/v/table/types.v b/vlib/v/table/types.v index 3d31970256..dc35814ab0 100644 --- a/vlib/v/table/types.v +++ b/vlib/v/table/types.v @@ -519,11 +519,11 @@ pub fn (mut t Table) register_builtin_type_symbols() { t.register_type_symbol(kind: .any, name: 'any', cname: 'any', mod: 'builtin') t.register_type_symbol( kind: .any_float - name: 'untyped float' + name: 'float literal' cname: 'any_float' mod: 'builtin' ) - t.register_type_symbol(kind: .any_int, name: 'untyped int', cname: 'any_int', mod: 'builtin') + t.register_type_symbol(kind: .any_int, name: 'int literal', cname: 'any_int', mod: 'builtin') } [inline] @@ -704,10 +704,19 @@ pub: variants []Type } +// human readable type name pub fn (table &Table) type_to_str(t Type) string { return table.type_to_str_using_aliases(t, map[string]string{}) } +// type name in code (for builtin) +pub fn (table &Table) type_to_code(t Type) string { + match t { + any_int_type, any_flt_type { return table.get_type_symbol(t).kind.str() } + else { return table.type_to_str_using_aliases(t, map[string]string{}) } + } +} + // import_aliases is a map of imported symbol aliases 'module.Type' => 'Type' pub fn (table &Table) type_to_str_using_aliases(t Type, import_aliases map[string]string) string { sym := table.get_type_symbol(t)