mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: wrap match branch expressions (#8190)
This commit is contained in:
parent
4779a273bf
commit
b44c08aff0
@ -1187,7 +1187,11 @@ pub fn (expr Expr) position() token.Position {
|
||||
AnonFn {
|
||||
return expr.decl.pos
|
||||
}
|
||||
ArrayInit, AsCast, Assoc, AtExpr, BoolLiteral, CallExpr, CastExpr, ChanInit, CharLiteral, ConcatExpr, Comment, EnumVal, FloatLiteral, GoExpr, Ident, IfExpr, IndexExpr, IntegerLiteral, Likely, LockExpr, MapInit, MatchExpr, None, OrExpr, ParExpr, PostfixExpr, PrefixExpr, RangeExpr, SelectExpr, SelectorExpr, SizeOf, SqlExpr, StringInterLiteral, StringLiteral, StructInit, Type, TypeOf, UnsafeExpr {
|
||||
ArrayInit, AsCast, Assoc, AtExpr, BoolLiteral, CallExpr, CastExpr, ChanInit, CharLiteral,
|
||||
ConcatExpr, Comment, EnumVal, FloatLiteral, GoExpr, Ident, IfExpr, IndexExpr, IntegerLiteral,
|
||||
Likely, LockExpr, MapInit, MatchExpr, None, OrExpr, ParExpr, PostfixExpr, PrefixExpr,
|
||||
RangeExpr, SelectExpr, SelectorExpr, SizeOf, SqlExpr, StringInterLiteral, StringLiteral,
|
||||
StructInit, Type, TypeOf, UnsafeExpr {
|
||||
return expr.pos
|
||||
}
|
||||
ArrayDecompose {
|
||||
@ -1272,7 +1276,9 @@ pub:
|
||||
|
||||
pub fn (stmt Stmt) position() token.Position {
|
||||
match stmt {
|
||||
AssertStmt, AssignStmt, Block, BranchStmt, CompFor, ConstDecl, DeferStmt, EnumDecl, ExprStmt, FnDecl, ForCStmt, ForInStmt, ForStmt, GotoLabel, GotoStmt, Import, Return, StructDecl, GlobalDecl, HashStmt, InterfaceDecl, Module, SqlStmt {
|
||||
AssertStmt, AssignStmt, Block, BranchStmt, CompFor, ConstDecl, DeferStmt, EnumDecl, ExprStmt,
|
||||
FnDecl, ForCStmt, ForInStmt, ForStmt, GotoLabel, GotoStmt, Import, Return, StructDecl,
|
||||
GlobalDecl, HashStmt, InterfaceDecl, Module, SqlStmt {
|
||||
return stmt.pos
|
||||
}
|
||||
GoStmt {
|
||||
@ -1306,7 +1312,8 @@ pub fn (node Node) position() token.Position {
|
||||
StructField {
|
||||
return node.pos.extend(node.type_pos)
|
||||
}
|
||||
MatchBranch, SelectBranch, Field, EnumField, ConstField, StructInitField, GlobalField, table.Param {
|
||||
MatchBranch, SelectBranch, Field, EnumField, ConstField, StructInitField, GlobalField,
|
||||
table.Param {
|
||||
return node.pos
|
||||
}
|
||||
IfBranch {
|
||||
@ -1336,7 +1343,8 @@ pub fn (node Node) children() []Node {
|
||||
StringInterLiteral, Assoc, ArrayInit {
|
||||
return node.exprs.map(Node(it))
|
||||
}
|
||||
SelectorExpr, PostfixExpr, UnsafeExpr, AsCast, ParExpr, IfGuardExpr, SizeOf, Likely, TypeOf, ArrayDecompose {
|
||||
SelectorExpr, PostfixExpr, UnsafeExpr, AsCast, ParExpr, IfGuardExpr, SizeOf, Likely,
|
||||
TypeOf, ArrayDecompose {
|
||||
children << node.expr
|
||||
}
|
||||
LockExpr, OrExpr {
|
||||
|
@ -2580,7 +2580,8 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
|
||||
right.position())
|
||||
}
|
||||
}
|
||||
.and_assign, .or_assign, .xor_assign, .mod_assign, .left_shift_assign, .right_shift_assign {
|
||||
.and_assign, .or_assign, .xor_assign, .mod_assign, .left_shift_assign, .right_shift_assign
|
||||
{
|
||||
if !left_sym.is_int() &&
|
||||
!c.table.get_final_type_symbol(left_type_unwrapped).is_int()
|
||||
{
|
||||
|
@ -1773,6 +1773,7 @@ pub fn (mut f Fmt) match_expr(it ast.MatchExpr) {
|
||||
if j < branch.exprs.len - 1 {
|
||||
f.write(', ')
|
||||
}
|
||||
f.wrap_long_line(3, false)
|
||||
}
|
||||
f.is_mbranch_expr = false
|
||||
} else {
|
||||
|
@ -30,3 +30,20 @@ fn match_branch_comment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn really_long_branch_exprs() {
|
||||
match x {
|
||||
ArrayInit, AsCast, Assoc, AtExpr, BoolLiteral, CallExpr, CastExpr, ChanInit, CharLiteral,
|
||||
ConcatExpr, Comment, EnumVal, FloatLiteral, GoExpr, Ident, IfExpr, IndexExpr, IntegerLiteral,
|
||||
Likely, LockExpr, MapInit, MatchExpr, None, OrExpr, ParExpr, PostfixExpr, PrefixExpr,
|
||||
RangeExpr, SelectExpr, SelectorExpr, SizeOf, SqlExpr, StringInterLiteral, StringLiteral,
|
||||
StructInit, Type, TypeOf, UnsafeExpr {
|
||||
return expr.pos
|
||||
}
|
||||
InfixExpr {
|
||||
Foo{
|
||||
x: 3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,3 +34,16 @@ fn match_branch_comment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn really_long_branch_exprs() {
|
||||
match x {
|
||||
ArrayInit, AsCast, Assoc, AtExpr, BoolLiteral, CallExpr, CastExpr, ChanInit, CharLiteral, ConcatExpr, Comment, EnumVal, FloatLiteral, GoExpr, Ident, IfExpr, IndexExpr, IntegerLiteral, Likely, LockExpr, MapInit, MatchExpr, None, OrExpr, ParExpr, PostfixExpr, PrefixExpr, RangeExpr, SelectExpr, SelectorExpr, SizeOf, SqlExpr, StringInterLiteral, StringLiteral, StructInit, Type, TypeOf, UnsafeExpr {
|
||||
return expr.pos
|
||||
}
|
||||
InfixExpr {
|
||||
Foo{
|
||||
x: 3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -759,7 +759,8 @@ pub fn (table &Table) type_to_str_using_aliases(t Type, import_aliases map[strin
|
||||
.int_literal, .float_literal {
|
||||
res = sym.name
|
||||
}
|
||||
.i8, .i16, .int, .i64, .byte, .u16, .u32, .u64, .f32, .f64, .char, .rune, .string, .bool, .none_, .byteptr, .voidptr, .charptr {
|
||||
.i8, .i16, .int, .i64, .byte, .u16, .u32, .u64, .f32, .f64, .char, .rune, .string, .bool,
|
||||
.none_, .byteptr, .voidptr, .charptr {
|
||||
// primitive types
|
||||
res = sym.kind.str()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user