checker: minor c2v fixes
parent
11113e43e7
commit
6d72209363
|
@ -46,10 +46,10 @@ jobs:
|
||||||
run: ./v test-fixed
|
run: ./v test-fixed
|
||||||
- name: Test building v tools
|
- name: Test building v tools
|
||||||
run: ./v build-tools
|
run: ./v build-tools
|
||||||
- name: v vet
|
# - name: v vet # TODO bring back v vet on linux-tcc
|
||||||
run: |
|
# run: |
|
||||||
./v vet vlib/sqlite
|
# ./v vet vlib/sqlite
|
||||||
./v vet vlib/v
|
# ./v vet vlib/v
|
||||||
- name: v fmt
|
- name: v fmt
|
||||||
run: |
|
run: |
|
||||||
./v fmt -verify vlib/v/checker/checker.v
|
./v fmt -verify vlib/v/checker/checker.v
|
||||||
|
@ -124,6 +124,10 @@ jobs:
|
||||||
run: ./v test-fixed
|
run: ./v test-fixed
|
||||||
- name: Build examples
|
- name: Build examples
|
||||||
run: ./v build-examples
|
run: ./v build-examples
|
||||||
|
- name: v vet
|
||||||
|
run: |
|
||||||
|
./v vet vlib/sqlite
|
||||||
|
./v vet vlib/v
|
||||||
- name: Cross-compilation to Linux
|
- name: Cross-compilation to Linux
|
||||||
run: ./v -os linux cmd/v
|
run: ./v -os linux cmd/v
|
||||||
# - name: Test vsh
|
# - name: Test vsh
|
||||||
|
|
|
@ -91,8 +91,7 @@ pub fn (mut c Checker) check_basic(got, expected table.Type) bool {
|
||||||
// TODO
|
// TODO
|
||||||
// accept [] when an expected type is an array
|
// accept [] when an expected type is an array
|
||||||
if got_type_sym.kind == .array &&
|
if got_type_sym.kind == .array &&
|
||||||
got_type_sym.name == 'array_void' &&
|
got_type_sym.name == 'array_void' && exp_type_sym.kind == .array {
|
||||||
exp_type_sym.kind == .array {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// type alias
|
// type alias
|
||||||
|
@ -112,7 +111,7 @@ pub fn (mut c Checker) check_basic(got, expected table.Type) bool {
|
||||||
return false
|
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
|
got_info := got_type_sym.info as table.FnType
|
||||||
exp_info := exp_type_sym.info as table.FnType
|
exp_info := exp_type_sym.info as table.FnType
|
||||||
got_fn := got_info.func
|
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 {
|
if exp_arg_is_ptr != got_arg_is_ptr {
|
||||||
exp_arg_pointedness := if exp_arg_is_ptr { 'a pointer' } else { 'NOT a pointer' }
|
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' }
|
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
|
return false
|
||||||
}
|
}
|
||||||
if !c.check_basic(got_arg.typ, exp_arg.typ) {
|
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)
|
typ := c.table.unalias_num_type(ftyp)
|
||||||
mut fmt := node.fmts[i]
|
mut fmt := node.fmts[i]
|
||||||
// analyze and validate format specifier
|
// 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])
|
c.error('unknown format specifier `${fmt:c}`', node.fmt_poss[i])
|
||||||
}
|
}
|
||||||
if fmt == `_` { // set default representation for type if none has been given
|
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
|
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) {
|
if c.table.sumtype_has_variant(a, b) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -659,7 +659,7 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
|
||||||
infix_expr.pos)
|
infix_expr.pos)
|
||||||
}
|
}
|
||||||
// Dual sides check (compatibility check)
|
// 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
|
// for type-unresolved consts
|
||||||
if left_type == table.void_type || right_type == table.void_type {
|
if left_type == table.void_type || right_type == table.void_type {
|
||||||
return 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 {
|
assign_stmt.op !in [.assign, .decl_assign] && !c.inside_unsafe {
|
||||||
c.warn('pointer arithmetic is only allowed in `unsafe` blocks', assign_stmt.pos)
|
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 {
|
if c.pref.translated {
|
||||||
// TODO fix this in C2V instead, for example cast enums to int before using `|` on them.
|
// TODO fix this in C2V instead, for example cast enums to int before using `|` on them.
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
// Single side check
|
// Single side check
|
||||||
match assign_stmt.op {
|
match assign_stmt.op {
|
||||||
|
@ -1774,12 +1780,6 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
|
||||||
}
|
}
|
||||||
else {}
|
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())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue