Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fix_struct_c_init
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed May 17, 2024
2 parents 4362d5f + 2a614bd commit 6463886
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/module_docs_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ on:
paths:
- 'vlib/**.v'
- 'vlib/**.md'
- 'cmd/tools/vdoc/**.v'
- '**/module_docs_ci.yml'
push:
paths:
- 'vlib/**.v'
- 'vlib/**.md'
- 'cmd/tools/vdoc/**.v'
- '**/module_docs_ci.yml'

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/other_ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Other CI

on:
workflow_dispatch:
push:
paths-ignore:
- '**.md'
Expand Down Expand Up @@ -101,17 +102,17 @@ jobs:
./v retry -- sudo apt update
./v retry -- sudo apt install --quiet -y libsodium-dev libssl-dev sqlite3 libsqlite3-dev postgresql libpq-dev valgrind
./v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev xfonts-75dpi xfonts-base
./v retry -- sudo apt install --quiet -y g++-9 g++-11
./v retry -- sudo apt install --quiet -y g++-9 g++-10
- name: g++-9 version
run: g++-9 --version
- name: V self compilation with g++ and -std=c++11
run: ./v -cc g++-9 -no-std -cflags -std=c++11 -o v2 cmd/v && ./v2 -cc g++-9 -no-std -cflags -std=c++11 -o v3 cmd/v

- name: g++-11 version
run: g++-11 --version
- name: g++-10 version
run: g++-10 --version
- name: V self compilation with g++ and -std=c++20
run: ./v -cc g++-11 -no-std -cflags -std=c++20 -o v2 cmd/v && ./v2 -cc g++-11 -no-std -cflags -std=c++20 -o v3 cmd/v
run: ./v -cc g++-10 -no-std -cflags -std=c++20 -o v2 cmd/v && ./v2 -cc g++-10 -no-std -cflags -std=c++20 -o v3 cmd/v

# NB: this does not mean it runs, but at least keeps it from regressing
- name: Ensure V can be compiled with -autofree
Expand Down
29 changes: 17 additions & 12 deletions cmd/tools/vdoc/files.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import os

struct IgnoreRules {
mut:
patterns map[string]bool = {
'testdata': true
'tests': true
'*_test.v': true
// Ignore patterns use the path with a `.vdocignore` file as a base. E.g.:
// `{'<path>': ['<pattern1>', '<pattern2>'], '<path/subpath>': ['<pattern3>']}`
patterns map[string][]string = {
// Default ignore patterns.
'': ['testdata', 'tests', '*_test.v']
}
paths map[string]bool
}
Expand All @@ -25,19 +26,23 @@ fn get_modules(path string) []string {

fn get_paths(path string, mut ignore_rules IgnoreRules) []string {
mut res := []string{}
for p in os.ls(path) or { return [] } {
outer: for p in os.ls(path) or { return [] } {
ignore_rules.get(path)
fp := os.join_path(path, p)
if fp in ignore_rules.paths {
continue
}
is_dir := os.is_dir(fp)
if ignore_rules.patterns.keys().any(p == it
|| (it.contains('*') && p.ends_with(it.all_after('*')))
|| (is_dir && it.ends_with('/') && fp.ends_with(it.trim_right('/')))
|| (!it.ends_with('/') && it.contains('/') && fp.contains(it)))
{
continue
for ignore_path, patterns in ignore_rules.patterns {
if fp.starts_with(ignore_path) {
if patterns.any(p == it
|| (it.contains('*') && p.ends_with(it.all_after('*')))
|| (is_dir && it.ends_with('/') && fp.ends_with(it.trim_right('/')))
|| (!it.ends_with('/') && it.contains('/') && fp.contains(it)))
{
continue outer
}
}
}
if is_dir {
res << get_paths(fp, mut ignore_rules)
Expand Down Expand Up @@ -73,7 +78,7 @@ fn (mut ignore_rules IgnoreRules) get(path string) {
// `/a` should ignore `/a` but not `/b/a`. While `a` should ignore `/a` and `/b/a`.
ignore_rules.paths[os.join_path(path, rule.trim_left('/'))] = true
} else {
ignore_rules.patterns[rule] = true
ignore_rules.patterns[path] << rule
}
}
}
1 change: 0 additions & 1 deletion vlib/net/unix/stream.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ fn (mut s StreamSocket) connect(socket_path string) ! {
addr := addrs[0]
// cast to the correct type
alen := addr.len()
eprintln(addr)

$if net_nonblocking_sockets ? {
res := $if is_coroutine ? {
Expand Down
6 changes: 6 additions & 0 deletions vlib/v/checker/infix.v
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
}
}

if ((unwrapped_left_type.is_ptr() && !node.left.is_auto_deref_var())
|| (unwrapped_right_type.is_ptr() && !node.right.is_auto_deref_var()))
&& node.op !in [.plus, .minus] {
c.error('infix `${node.op}` is not defined for pointer values', left_right_pos)
}

if !c.pref.translated && left_sym.kind in [.array, .array_fixed, .map, .struct_] {
if left_sym.has_method_with_generic_parent(node.op.str()) {
if method := left_sym.find_method_with_generic_parent(node.op.str()) {
Expand Down
14 changes: 14 additions & 0 deletions vlib/v/checker/tests/disallow_pointer_arithmetic_err.out
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,24 @@ vlib/v/checker/tests/disallow_pointer_arithmetic_err.vv:5:7: error: invalid oper
| ~~~~~
6 | _ := p * 2 //should be error
7 | _ := p + 5 //OK but only in unsafe block, r is *int
vlib/v/checker/tests/disallow_pointer_arithmetic_err.vv:5:7: error: infix `*` is not defined for pointer values
3 | p := &x
4 | _ := p + p //should be error
5 | _ := p * p //should be error
| ~~~~~
6 | _ := p * 2 //should be error
7 | _ := p + 5 //OK but only in unsafe block, r is *int
vlib/v/checker/tests/disallow_pointer_arithmetic_err.vv:6:7: error: invalid operator `*` to `&int` and `int literal`
4 | _ := p + p //should be error
5 | _ := p * p //should be error
6 | _ := p * 2 //should be error
| ~~~~~
7 | _ := p + 5 //OK but only in unsafe block, r is *int
8 | _ := p - p //OK even in safe code, but n should be isize
vlib/v/checker/tests/disallow_pointer_arithmetic_err.vv:6:7: error: infix `*` is not defined for pointer values
4 | _ := p + p //should be error
5 | _ := p * p //should be error
6 | _ := p * 2 //should be error
| ~~~~~
7 | _ := p + 5 //OK but only in unsafe block, r is *int
8 | _ := p - p //OK even in safe code, but n should be isize
14 changes: 14 additions & 0 deletions vlib/v/checker/tests/invalid_op_ptr_err.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
vlib/v/checker/tests/invalid_op_ptr_err.vv:3:6: error: infix `*` is not defined for pointer values
1 | num := 10
2 | p := &num
3 | x := 5 * p
| ~~~~~
4 | y := 5 / p
5 | dump(x)
vlib/v/checker/tests/invalid_op_ptr_err.vv:4:6: error: infix `/` is not defined for pointer values
2 | p := &num
3 | x := 5 * p
4 | y := 5 / p
| ~~~~~
5 | dump(x)
6 | dump(p)
7 changes: 7 additions & 0 deletions vlib/v/checker/tests/invalid_op_ptr_err.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
num := 10
p := &num
x := 5 * p
y := 5 / p
dump(x)
dump(p)
dump(y)
14 changes: 14 additions & 0 deletions vlib/v/checker/tests/pointer_ops.out
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ vlib/v/checker/tests/pointer_ops.vv:15:3: error: invalid operator `%` to `&Foo`
| ~~~~~~~
16 | }
17 | }
vlib/v/checker/tests/pointer_ops.vv:15:3: error: infix `%` is not defined for pointer values
13 | _ = p[3]
14 | mut foo := &Foo{}
15 | foo % 3
| ~~~~~~~
16 | }
17 | }
vlib/v/checker/tests/pointer_ops.vv:15:3: error: mismatched types `&Foo` and `int literal`
13 | _ = p[3]
14 | mut foo := &Foo{}
Expand Down Expand Up @@ -117,6 +124,13 @@ vlib/v/checker/tests/pointer_ops.vv:30:3: error: invalid operator `%` to `&Foo`
| ~~~~~~~
31 | }
32 | }
vlib/v/checker/tests/pointer_ops.vv:30:3: error: infix `%` is not defined for pointer values
28 | _ = p[3]
29 | mut foo := &Foo{}
30 | foo % 3
| ~~~~~~~
31 | }
32 | }
vlib/v/checker/tests/pointer_ops.vv:30:3: error: mismatched types `&Foo` and `int literal`
28 | _ = p[3]
29 | mut foo := &Foo{}
Expand Down

0 comments on commit 6463886

Please sign in to comment.