`as` casting

pull/3271/head
Alexander Medvednikov 2019-12-30 10:45:56 +01:00
parent 2d597d7804
commit cba6a6fdea
3 changed files with 18 additions and 2 deletions

View File

@ -6,7 +6,7 @@ import json
import sync
const (
NR_THREADS = 4
nr_threads = 4
)
struct Story {
@ -73,7 +73,7 @@ fn main() {
fetcher.mu = &mtx
fetcher.wg = &wg
fetcher.wg.add(ids.len)
for i := 0; i < NR_THREADS; i++ {
for i := 0; i < nr_threads; i++ {
go fetcher.fetch()
}
fetcher.wg.wait()

View File

@ -44,6 +44,10 @@ fn test_float_equal_operator() {
assert a.gtbit(1)
assert a >= 1
assert a.gebit(1)
f := 1.2
ab := f as int
assert ab == 1
}
fn test_str_methods() {

View File

@ -60,6 +60,18 @@ fn (p mut Parser) bool_expression() string {
p.gen('}, sizeof($typ) ), .typ = SumType_${tt} }')//${val}_type }')
}
}
// `as` cast
// TODO remove copypasta
if p.tok == .key_as {
p.next()
cast_typ := p.get_type()
if typ == cast_typ {
p.warn('casting `$typ` to `$cast_typ` is not needed')
}
p.cgen.set_placeholder(start_ph, '($cast_typ)(')
p.gen(')')
return cast_typ
}
return typ
}