Merge branch 'master' of github.com:hungrybluedev/v
commit
7aa39cbc5e
|
|
@ -1099,7 +1099,7 @@ fn generate_scalar(size int) ?Scalar {
|
|||
return reflect.ValueOf(s)
|
||||
*/
|
||||
mut s := edwards25519.sc_zero
|
||||
diceroll := rand.intn(100) or {0}
|
||||
diceroll := rand.intn(100) or { 0 }
|
||||
match true {
|
||||
/*
|
||||
case diceroll == 0:
|
||||
|
|
|
|||
|
|
@ -530,7 +530,8 @@ pub mut:
|
|||
has_await bool // 'true' if this function uses JS.await
|
||||
//
|
||||
comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl
|
||||
next_comments []Comment // coments that are one line after the decl; used for InterfaceDecl
|
||||
end_comments []Comment // comments *after* header declarations. E.g.: `fn C.C_func(x int) int // Comment`
|
||||
next_comments []Comment // comments that are one line after the decl; used for InterfaceDecl
|
||||
//
|
||||
source_file &File = 0
|
||||
scope &Scope
|
||||
|
|
|
|||
|
|
@ -1267,7 +1267,7 @@ pub fn (t &TypeSymbol) find_method_with_generic_parent(name string) ?Fn {
|
|||
mut method := x
|
||||
generic_names := parent_sym.info.generic_types.map(table.sym(it).name)
|
||||
return_sym := table.sym(method.return_type)
|
||||
if return_sym.kind == .struct_ {
|
||||
if return_sym.kind in [.struct_, .interface_, .sum_type] {
|
||||
method.return_type = table.unwrap_generic_type(method.return_type,
|
||||
generic_names, t.info.concrete_types)
|
||||
} else {
|
||||
|
|
@ -1290,7 +1290,6 @@ pub fn (t &TypeSymbol) find_method_with_generic_parent(name string) ?Fn {
|
|||
}
|
||||
else {}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -842,10 +842,25 @@ pub fn (mut f Fmt) const_decl(node ast.ConstDecl) {
|
|||
f.write(strings.repeat(` `, align_infos[align_idx].max - field.name.len))
|
||||
f.write('= ')
|
||||
f.expr(field.expr)
|
||||
f.writeln('')
|
||||
if node.is_block {
|
||||
f.writeln('')
|
||||
} else {
|
||||
// Write out single line comments after const expr if present
|
||||
// E.g.: `const x = 1 // <comment>`
|
||||
if node.end_comments.len > 0 && node.end_comments[0].text.contains('\n') {
|
||||
f.writeln('\n')
|
||||
}
|
||||
f.comments(node.end_comments, inline: true)
|
||||
}
|
||||
prev_field = field
|
||||
}
|
||||
f.comments_after_last_field(node.end_comments)
|
||||
|
||||
if node.is_block {
|
||||
f.comments_after_last_field(node.end_comments)
|
||||
} else if node.end_comments.len == 0 {
|
||||
// If no single line comments after the const expr is present
|
||||
f.writeln('')
|
||||
}
|
||||
if node.is_block {
|
||||
f.indent--
|
||||
f.writeln(')\n')
|
||||
|
|
@ -899,6 +914,26 @@ pub fn (mut f Fmt) enum_decl(node ast.EnumDecl) {
|
|||
pub fn (mut f Fmt) fn_decl(node ast.FnDecl) {
|
||||
f.attrs(node.attrs)
|
||||
f.write(node.stringify(f.table, f.cur_mod, f.mod2alias)) // `Expr` instead of `ast.Expr` in mod ast
|
||||
// Handle trailing comments after fn header declarations
|
||||
if node.end_comments.len > 0 {
|
||||
first_comment := node.end_comments[0]
|
||||
if first_comment.text.contains('\n') {
|
||||
f.writeln('\n')
|
||||
} else {
|
||||
f.write(' ')
|
||||
}
|
||||
f.comment(first_comment)
|
||||
if node.end_comments.len > 1 {
|
||||
f.writeln('\n')
|
||||
comments := node.end_comments[1..]
|
||||
for i, comment in comments {
|
||||
f.comment(comment)
|
||||
if i != comments.len - 1 {
|
||||
f.writeln('\n')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
f.fn_body(node)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
// leave
|
||||
const one = 1 // leave
|
||||
|
||||
// move
|
||||
|
||||
const two = 2
|
||||
|
||||
/*
|
||||
move
|
||||
*/
|
||||
|
||||
const three = 3 // rewrite and leave
|
||||
|
||||
// leave
|
||||
const four = 4 // leave
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
// leave
|
||||
const one = 1 // leave
|
||||
// move
|
||||
|
||||
const two = 2 /* move
|
||||
*/
|
||||
|
||||
const three = 3 /* rewrite and leave */
|
||||
|
||||
// leave
|
||||
const four = 4 // leave
|
||||
|
|
@ -2,3 +2,8 @@ const (
|
|||
fsm_state_array = ['init', 'state_a', 'state_b', 'state_c', 'exit'] // use as a first half key for map see fsm_state_ev_fn, the same order as in enum FSM_state
|
||||
fsm_event_array = ['ev1', 'ev2', 'ev3', 'ev4', 'ev5'] // use as a second half key for map see fsm_state_ev_fn, the same order as in enum FSM_event
|
||||
)
|
||||
|
||||
// Keep
|
||||
const one = 1 // Keep
|
||||
|
||||
// Keep
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
fn C.Mix_LoadMUS1(file byteptr) voidptr // *Mix_Music
|
||||
|
||||
fn C.Mix_LoadMUS2(file byteptr) voidptr //*Mix_Music
|
||||
|
||||
fn C.Mix_LoadMUS3(file byteptr) voidptr // 1
|
||||
|
||||
// 2
|
||||
|
||||
// 3
|
||||
|
||||
// Loads music
|
||||
fn C.Mix_LoadMUS4(file byteptr) voidptr
|
||||
|
||||
/*
|
||||
Test
|
||||
*/
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fn C.Mix_LoadMUS1(file byteptr) voidptr // *Mix_Music
|
||||
|
||||
fn C.Mix_LoadMUS2(file byteptr) voidptr /* *Mix_Music */
|
||||
|
||||
fn C.Mix_LoadMUS3(file byteptr) voidptr /* 1 */ /* 2 */ /* 3 */
|
||||
|
||||
// Loads music
|
||||
fn C.Mix_LoadMUS4(file byteptr) voidptr /* Test
|
||||
*/
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
fn C.Mix_LoadMUS1(file byteptr) voidptr // Mix_Music
|
||||
|
||||
fn C.Mix_LoadMUS2(file byteptr) voidptr // Mix_Music 2
|
||||
|
||||
// Comment
|
||||
|
|
@ -376,9 +376,7 @@ pub fn (mut p Parser) expr_with_left(left ast.Expr, precedence int, is_stmt_iden
|
|||
return node
|
||||
}
|
||||
p.is_stmt_ident = is_stmt_ident
|
||||
} else if p.tok.kind in [.lsbr, .nilsbr]
|
||||
&& (p.inside_fn || p.tok.line_nr == p.prev_tok.line_nr) {
|
||||
// node = p.index_expr(node)
|
||||
} else if p.tok.kind in [.lsbr, .nilsbr] && p.tok.line_nr == p.prev_tok.line_nr {
|
||||
if p.tok.kind == .nilsbr {
|
||||
node = p.index_expr(node, true)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -527,6 +527,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
|||
is_builtin: p.builtin_mod || p.mod in util.builtin_module_parts
|
||||
scope: p.scope
|
||||
label_names: p.label_names
|
||||
end_comments: p.eat_comments(same_line: true)
|
||||
}
|
||||
if generic_names.len > 0 {
|
||||
p.table.register_fn_generic_types(fn_decl.fkey())
|
||||
|
|
|
|||
|
|
@ -3292,6 +3292,8 @@ fn (mut p Parser) const_decl() ast.ConstDecl {
|
|||
p.top_level_statement_end()
|
||||
if is_block {
|
||||
p.check(.rpar)
|
||||
} else {
|
||||
comments << p.eat_comments(same_line: true)
|
||||
}
|
||||
return ast.ConstDecl{
|
||||
pos: start_pos.extend_with_last_line(const_pos, p.prev_tok.line_nr)
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@ const x = 4
|
|||
[deprecated]
|
||||
fn g() {
|
||||
a := [3]
|
||||
// indexing is currently allowed on next line
|
||||
_ = a
|
||||
[0]
|
||||
_ = a[0]
|
||||
}
|
||||
|
||||
const y = 5
|
||||
|
|
@ -16,7 +14,5 @@ const z = 6
|
|||
[typedef]
|
||||
struct C.Foo{}
|
||||
|
||||
// test implicit main allows indexing on next line
|
||||
a := [3]
|
||||
_ := a
|
||||
[0]
|
||||
_ := a[0]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
struct Empty {
|
||||
empty string
|
||||
}
|
||||
|
||||
fn print_error() ?[]Empty {
|
||||
mut test := []Empty{}
|
||||
test << Empty{
|
||||
empty: 'Test'
|
||||
}
|
||||
if test[0].empty != '' {
|
||||
return error('Not empty')
|
||||
}
|
||||
return test
|
||||
}
|
||||
|
||||
fn test_option_expr_with_array_value() {
|
||||
test_error := print_error() or {
|
||||
eprintln(err)
|
||||
[]Empty{}
|
||||
}
|
||||
println(test_error)
|
||||
assert '$test_error' == '[]'
|
||||
}
|
||||
Loading…
Reference in New Issue