mirror of
https://github.com/vlang/v.git
synced 2025-09-17 00:12:26 +03:00
Compare commits
No commits in common. "dbd5b5f56cb7451949eaa72ec8534eac7b6a6cd1" and "f6b60e4d9f4213f5fa08651da7af7b4ef2806ce1" have entirely different histories.
dbd5b5f56c
...
f6b60e4d9f
10 changed files with 13 additions and 72 deletions
|
@ -441,7 +441,7 @@ fn run_repl(workdir string, vrepl_prefix string) int {
|
|||
prompt = '... '
|
||||
}
|
||||
oline := r.get_one_line(prompt) or { break }
|
||||
line := oline.all_before('//').trim_space()
|
||||
line := oline.trim_space()
|
||||
if line == '' {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -124,10 +124,9 @@ pub:
|
|||
typ int // the internal TypeID of the field f,
|
||||
unaliased_typ int // if f's type was an alias of int, this will be TypeID(int)
|
||||
|
||||
attrs []string // the attributes of the field f
|
||||
is_pub bool // f is in a `pub:` section
|
||||
is_mut bool // f is in a `mut:` section
|
||||
is_embed bool // f is a embedded struct
|
||||
attrs []string // the attributes of the field f
|
||||
is_pub bool // f is in a `pub:` section
|
||||
is_mut bool // f is in a `mut:` section
|
||||
|
||||
is_shared bool // `f shared Abc`
|
||||
is_atomic bool // `f atomic int` , TODO
|
||||
|
|
|
@ -1398,7 +1398,7 @@ fn (mut c Checker) comptime_if_cond(mut cond ast.Expr, mut sb strings.Builder) (
|
|||
}
|
||||
ast.SelectorExpr {
|
||||
if c.comptime.comptime_for_field_var != '' && cond.expr is ast.Ident {
|
||||
if (cond.expr as ast.Ident).name == c.comptime.comptime_for_field_var && cond.field_name in ['is_mut', 'is_pub', 'is_embed', 'is_shared', 'is_atomic', 'is_option', 'is_array', 'is_map', 'is_chan', 'is_struct', 'is_alias', 'is_enum'] {
|
||||
if (cond.expr as ast.Ident).name == c.comptime.comptime_for_field_var && cond.field_name in ['is_mut', 'is_pub', 'is_shared', 'is_atomic', 'is_option', 'is_array', 'is_map', 'is_chan', 'is_struct', 'is_alias', 'is_enum'] {
|
||||
is_true = c.type_resolver.get_comptime_selector_bool_field(cond.field_name)
|
||||
sb.write_string('${is_true}')
|
||||
return is_true, true
|
||||
|
|
|
@ -221,13 +221,10 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !node.is_comptime || (node.is_comptime && comptime_match_branch_result) {
|
||||
if node.is_expr {
|
||||
c.stmts_ending_with_expression(mut branch.stmts, c.expected_or_type)
|
||||
} else {
|
||||
c.stmts(mut branch.stmts)
|
||||
}
|
||||
if node.is_expr {
|
||||
c.stmts_ending_with_expression(mut branch.stmts, c.expected_or_type)
|
||||
} else {
|
||||
c.stmts(mut branch.stmts)
|
||||
}
|
||||
c.smartcast_mut_pos = token.Pos{}
|
||||
c.smartcast_cond_pos = token.Pos{}
|
||||
|
|
|
@ -740,7 +740,6 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) {
|
|||
g.writeln('\t${node.val_var}.unaliased_typ = ${int(unaliased_styp.idx())};\t// ${g.table.type_to_str(unaliased_styp)}')
|
||||
g.writeln('\t${node.val_var}.is_pub = ${field.is_pub};')
|
||||
g.writeln('\t${node.val_var}.is_mut = ${field.is_mut};')
|
||||
g.writeln('\t${node.val_var}.is_embed = ${field.is_embed};')
|
||||
|
||||
g.writeln('\t${node.val_var}.is_shared = ${field.typ.has_flag(.shared_f)};')
|
||||
g.writeln('\t${node.val_var}.is_atomic = ${field.typ.has_flag(.atomic_f)};')
|
||||
|
@ -781,12 +780,7 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) {
|
|||
if g.pref.translated && node.typ.is_number() {
|
||||
g.writeln('_const_main__${val};')
|
||||
} else {
|
||||
node_sym := g.table.sym(node.typ)
|
||||
if node_sym.info is ast.Alias {
|
||||
g.writeln('${g.styp(node_sym.info.parent_type)}__${val};')
|
||||
} else {
|
||||
g.writeln('${g.styp(node.typ)}__${val};')
|
||||
}
|
||||
g.writeln('${g.styp(node.typ)}__${val};')
|
||||
}
|
||||
enum_attrs := sym.info.attrs[val]
|
||||
if enum_attrs.len == 0 {
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
math.pi
|
||||
math.pi // some comment
|
||||
===output===
|
||||
3.141592653589793
|
||||
3.141592653589793
|
|
@ -5,8 +5,6 @@ enum CharacterGroup {
|
|||
special
|
||||
}
|
||||
|
||||
type AnotherCharGroup = CharacterGroup
|
||||
|
||||
fn (self CharacterGroup) value() string {
|
||||
return match self {
|
||||
.chars { 'first' }
|
||||
|
@ -35,21 +33,3 @@ fn test_main() {
|
|||
assert values == [CharacterGroup.chars, CharacterGroup.alphanumerics, CharacterGroup.numeric,
|
||||
CharacterGroup.special]
|
||||
}
|
||||
|
||||
fn test_alias_enum() {
|
||||
mut values := []EnumData{}
|
||||
$for entry in AnotherCharGroup.values {
|
||||
values << entry
|
||||
}
|
||||
assert values[0].value == int(CharacterGroup.chars)
|
||||
assert values[0].name == CharacterGroup.chars.str()
|
||||
|
||||
assert values[1].value == int(CharacterGroup.alphanumerics)
|
||||
assert values[1].name == CharacterGroup.alphanumerics.str()
|
||||
|
||||
assert values[2].value == int(CharacterGroup.numeric)
|
||||
assert values[2].name == CharacterGroup.numeric.str()
|
||||
|
||||
assert values[3].value == int(CharacterGroup.special)
|
||||
assert values[3].name == CharacterGroup.special.str()
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
struct App {
|
||||
Inner
|
||||
a string
|
||||
b string
|
||||
mut:
|
||||
|
@ -13,8 +12,6 @@ pub mut:
|
|||
h u8
|
||||
}
|
||||
|
||||
struct Inner {}
|
||||
|
||||
@['foo/bar/three']
|
||||
fn (mut app App) run() {
|
||||
}
|
||||
|
@ -88,16 +85,13 @@ fn test_comptime_for_fields() {
|
|||
assert field.name in ['d', 'e']
|
||||
}
|
||||
if field.is_mut {
|
||||
assert field.name in ['c', 'd', 'g', 'h', 'Inner']
|
||||
assert field.name in ['c', 'd', 'g', 'h']
|
||||
}
|
||||
if field.is_pub {
|
||||
assert field.name in ['e', 'f', 'g', 'h', 'Inner']
|
||||
assert field.name in ['e', 'f', 'g', 'h']
|
||||
}
|
||||
if field.is_pub && field.is_mut {
|
||||
assert field.name in ['g', 'h', 'Inner']
|
||||
}
|
||||
if field.is_embed {
|
||||
assert field.name == 'Inner'
|
||||
assert field.name in ['g', 'h']
|
||||
}
|
||||
if field.name == 'f' {
|
||||
assert sizeof(field) == 8
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
module main
|
||||
|
||||
fn func[T]() bool {
|
||||
$match T {
|
||||
u8, u16 {
|
||||
return true
|
||||
}
|
||||
$else {
|
||||
// return false
|
||||
$compile_error('fail')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn test_comptime_match_eval_only_true_branch() {
|
||||
assert func[u8]()
|
||||
}
|
|
@ -224,7 +224,6 @@ pub fn (mut t TypeResolver) get_comptime_selector_bool_field(field_name string)
|
|||
match field_name {
|
||||
'is_pub' { return field.is_pub }
|
||||
'is_mut' { return field.is_mut }
|
||||
'is_embed' { return field.is_embed }
|
||||
'is_shared' { return field_typ.has_flag(.shared_f) }
|
||||
'is_atomic' { return field_typ.has_flag(.atomic_f) }
|
||||
'is_option' { return field.typ.has_flag(.option) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue