parser: fix module type cast

pull/5565/head
yuyi 2020-06-29 23:15:40 +08:00 committed by GitHub
parent c69ef876c5
commit 9d845262b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -855,6 +855,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
else {}
}
}
mut is_mod_cast := false
if p.peek_tok.kind == .dot && !known_var &&
(language != .v || p.known_import(p.tok.lit) || p.mod.all_after_last('.') == p.tok.lit) {
if language == .c {
@ -864,6 +865,9 @@ pub fn (mut p Parser) name_expr() ast.Expr {
} else {
if p.tok.lit in p.imports {
p.register_used_import(p.tok.lit)
if p.peek_tok.kind == .dot && p.peek_tok2.lit[0].is_capital() {
is_mod_cast = true
}
}
// prepend the full import
mod = p.imports[p.tok.lit]
@ -884,9 +888,8 @@ pub fn (mut p Parser) name_expr() ast.Expr {
name_w_mod := p.prepend_mod(name)
// type cast. TODO: finish
// if name in table.builtin_type_names {
if !known_var && (name in p.table.type_idxs ||
name_w_mod in p.table.type_idxs) &&
name !in ['C.stat', 'C.sigaction'] {
if (!known_var && (name in p.table.type_idxs || name_w_mod in p.table.type_idxs) &&
name !in ['C.stat', 'C.sigaction']) || is_mod_cast {
// TODO handle C.stat()
mut to_typ := p.parse_type()
if p.is_amp {

View File

@ -0,0 +1,8 @@
import time
fn test_module_type_cast() {
a := time.Duration(5)
b := time.Duration(6)
//println(a+b)
assert a+b == 11
}