From 6d72209363851a4fca0a0f2406aeb55b9f7ba98a Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 11 Aug 2020 00:51:15 +0200 Subject: [PATCH] checker: minor c2v fixes --- .github/workflows/ci.yml | 38 ++++++++++++++++++++---------------- vlib/v/checker/check_types.v | 14 ++++++------- vlib/v/checker/checker.v | 16 +++++++-------- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2dc4ad6fd2..f995066d29 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,9 +28,9 @@ jobs: - uses: actions/checkout@v2 - name: Install dependencies run: | - sudo rm -f /etc/apt/sources.list.d/dotnetdev.list /etc/apt/sources.list.d/microsoft-prod.list; sudo apt-get update; + sudo rm -f /etc/apt/sources.list.d/dotnetdev.list /etc/apt/sources.list.d/microsoft-prod.list; sudo apt-get update; sudo apt-get install --quiet -y libglfw3 libglfw3-dev libfreetype6-dev libssl-dev sqlite3 libsqlite3-dev valgrind - ## sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev + ## sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev - name: Build v run: | echo $VFLAGS @@ -46,10 +46,10 @@ jobs: run: ./v test-fixed - name: Test building v tools run: ./v build-tools - - name: v vet - run: | - ./v vet vlib/sqlite - ./v vet vlib/v +# - name: v vet # TODO bring back v vet on linux-tcc +# run: | +# ./v vet vlib/sqlite +# ./v vet vlib/v - name: v fmt run: | ./v fmt -verify vlib/v/checker/checker.v @@ -97,7 +97,7 @@ jobs: ##brew install libpq openssl freetype ### these are *already installed* on Catalina ... brew uninstall --ignore-dependencies libpq ## libpq is a dependency of PHP brew install postgresql - brew install glfw + brew install glfw ## brew install sdl2 sdl2_ttf sdl2_mixer sdl2_image export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/opt/openssl/lib/" - name: Build V @@ -124,6 +124,10 @@ jobs: run: ./v test-fixed - name: Build examples run: ./v build-examples + - name: v vet + run: | + ./v vet vlib/sqlite + ./v vet vlib/v - name: Cross-compilation to Linux run: ./v -os linux cmd/v # - name: Test vsh @@ -151,8 +155,8 @@ jobs: node-version: 12.x - name: Install dependencies run: | - sudo rm -f /etc/apt/sources.list.d/dotnetdev.list /etc/apt/sources.list.d/microsoft-prod.list; - sudo apt-get update; + sudo rm -f /etc/apt/sources.list.d/dotnetdev.list /etc/apt/sources.list.d/microsoft-prod.list; + sudo apt-get update; sudo apt-get install --quiet -y postgresql libpq-dev libglfw3 libglfw3-dev libfreetype6-dev libssl-dev sqlite3 libsqlite3-dev valgrind ## sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev - name: Build V @@ -255,10 +259,10 @@ jobs: # node-version: 12.x # - name: Install dependencies # run: | -# sudo rm -f /etc/apt/sources.list.d/dotnetdev.list /etc/apt/sources.list.d/microsoft-prod.list; -# sudo apt-get update; +# sudo rm -f /etc/apt/sources.list.d/dotnetdev.list /etc/apt/sources.list.d/microsoft-prod.list; +# sudo apt-get update; # sudo apt-get install --quiet -y musl musl-tools libssl-dev sqlite3 libsqlite3-dev valgrind -# sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev +# sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev # - name: Build v # run: echo $VFLAGS && make -j4 && ./v -cg -o v cmd/v # # - name: Test v binaries @@ -424,11 +428,11 @@ jobs: - uses: actions/checkout@v2 - name: Install dependencies run: | - sudo rm -f /etc/apt/sources.list.d/dotnetdev.list /etc/apt/sources.list.d/microsoft-prod.list; - sudo apt-get update; - sudo apt-get install --quiet -y postgresql libpq-dev libglfw3 libglfw3-dev libfreetype6-dev libssl-dev sqlite3 libsqlite3-dev - sudo apt-get install --quiet -y valgrind g++-9 - ## sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev + sudo rm -f /etc/apt/sources.list.d/dotnetdev.list /etc/apt/sources.list.d/microsoft-prod.list; + sudo apt-get update; + sudo apt-get install --quiet -y postgresql libpq-dev libglfw3 libglfw3-dev libfreetype6-dev libssl-dev sqlite3 libsqlite3-dev + sudo apt-get install --quiet -y valgrind g++-9 + ## sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev - name: Build V run: make -j4 - name: g++ version diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index 724d1f865e..96143b9e5f 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -58,7 +58,7 @@ pub fn (mut c Checker) check_basic(got, expected table.Type) bool { } // TODO: this should no longer be needed // if expected == table.t_type && got == table.t_type { - // return true + // return true // } // # NOTE: use symbols from this point on for perf got_type_sym := t.get_type_symbol(got) @@ -91,8 +91,7 @@ pub fn (mut c Checker) check_basic(got, expected table.Type) bool { // TODO // accept [] when an expected type is an array if got_type_sym.kind == .array && - got_type_sym.name == 'array_void' && - exp_type_sym.kind == .array { + got_type_sym.name == 'array_void' && exp_type_sym.kind == .array { return true } // type alias @@ -112,7 +111,7 @@ pub fn (mut c Checker) check_basic(got, expected table.Type) bool { return false } -pub fn (mut c Checker) check_matching_function_symbols(got_type_sym &table.TypeSymbol, exp_type_sym &table.TypeSymbol) bool { +pub fn (mut c Checker) check_matching_function_symbols(got_type_sym, exp_type_sym &table.TypeSymbol) bool { got_info := got_type_sym.info as table.FnType exp_info := exp_type_sym.info as table.FnType got_fn := got_info.func @@ -132,7 +131,7 @@ pub fn (mut c Checker) check_matching_function_symbols(got_type_sym &table.TypeS if exp_arg_is_ptr != got_arg_is_ptr { exp_arg_pointedness := if exp_arg_is_ptr { 'a pointer' } else { 'NOT a pointer' } got_arg_pointedness := if got_arg_is_ptr { 'a pointer' } else { 'NOT a pointer' } - c.add_error_detail('`$exp_fn.name`\'s expected fn argument: `$exp_arg.name` is $exp_arg_pointedness, but the passed fn argument: `$got_arg.name` is $got_arg_pointedness') + c.add_error_detail("`$exp_fn.name`\'s expected fn argument: `$exp_arg.name` is $exp_arg_pointedness, but the passed fn argument: `$got_arg.name` is $got_arg_pointedness") return false } if !c.check_basic(got_arg.typ, exp_arg.typ) { @@ -310,7 +309,8 @@ pub fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) table.T typ := c.table.unalias_num_type(ftyp) mut fmt := node.fmts[i] // analyze and validate format specifier - if fmt !in [`E`, `F`, `G`, `e`, `f`, `g`, `d`, `u`, `x`, `X`, `o`, `c`, `s`, `p`, `_`] { + if fmt !in + [`E`, `F`, `G`, `e`, `f`, `g`, `d`, `u`, `x`, `X`, `o`, `c`, `s`, `p`, `_`] { c.error('unknown format specifier `${fmt:c}`', node.fmt_poss[i]) } if fmt == `_` { // set default representation for type if none has been given @@ -347,7 +347,7 @@ pub fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) table.T return table.string_type } -pub fn (c &Checker) check_sumtype_compatibility(a table.Type, b table.Type) bool { +pub fn (c &Checker) check_sumtype_compatibility(a, b table.Type) bool { if c.table.sumtype_has_variant(a, b) { return true } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 801bd5cda2..b509d9a1ac 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -659,7 +659,7 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type { infix_expr.pos) } // Dual sides check (compatibility check) - if !c.symmetric_check(right_type, left_type) { + if !c.symmetric_check(right_type, left_type) && !c.pref.translated { // for type-unresolved consts if left_type == table.void_type || right_type == table.void_type { return table.void_type @@ -1723,9 +1723,15 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) { assign_stmt.op !in [.assign, .decl_assign] && !c.inside_unsafe { c.warn('pointer arithmetic is only allowed in `unsafe` blocks', assign_stmt.pos) } + // Dual sides check (compatibility check) + if !is_blank_ident && !c.check_types(right_type_unwrapped, left_type_unwrapped) && + right_sym.kind != .placeholder { + c.error('cannot assign `$right_sym.name` to `$left.str()` of type `$left_sym.name`', + right.position()) + } if c.pref.translated { // TODO fix this in C2V instead, for example cast enums to int before using `|` on them. - return + continue } // Single side check match assign_stmt.op { @@ -1774,12 +1780,6 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) { } else {} } - // Dual sides check (compatibility check) - if !is_blank_ident && !c.check_types(right_type_unwrapped, left_type_unwrapped) && - right_sym.kind != .placeholder { - c.error('cannot assign `$right_sym.name` to `$left.str()` of type `$left_sym.name`', - right.position()) - } } }