allow defining methods on aliases

This commit is contained in:
Alexander Medvednikov 2019-07-10 14:18:21 +02:00
parent 00ea112b66
commit fba8443f30
3 changed files with 11 additions and 12 deletions

View file

@ -391,7 +391,7 @@ fn (p mut Parser) type_decl() {
// so specify "struct"
_struct := if !parent.contains('[') && !parent.starts_with('fn ') && !p.table.known_type(parent){'struct'} else { ''}
p.gen_typedef('typedef $_struct $nt_pair; // type alias name="$name" parent="$parent"')
p.table.register_type_with_parent(name, parent)
p.register_type_with_parent(name, parent)
}
fn (p mut Parser) interface_method(field_name, receiver string) &Fn {
@ -1066,7 +1066,7 @@ fn (p mut Parser) assign_statement(v Var, ph int, is_map bool) {
p.log('assign_statement() name=$v.name tok=')
tok := p.tok
if !v.is_mut && !v.is_arg && !p.pref.translated && !v.is_global{
p.error('`$v.name` is imkey_mut')
p.error('`$v.name` is immutable')
}
is_str := v.typ == 'string'
switch tok {
@ -1488,7 +1488,7 @@ fn (p mut Parser) var_expr(v Var) string {
// a++ and a--
if p.tok == .inc || p.tok == .dec {
if !v.is_mut && !v.is_arg && !p.pref.translated {
p.error('`$v.name` is imkey_mut')
p.error('`$v.name` is immutable')
}
if typ != 'int' {
if !p.pref.translated && !is_number_type(typ) {
@ -1567,7 +1567,7 @@ fn (p mut Parser) dot(str_typ string, method_ph int) string {
modifying := next.is_assign() || next == .inc || next == .dec
is_vi := p.fileis('vi')
if !p.builtin_pkg && !p.pref.translated && modifying && !field.is_mut && !is_vi {
p.error('cannot modify imkey_mut field `$field_name` (type `$typ.name`)')
p.error('cannot modify immutable field `$field_name` (type `$typ.name`)')
}
if !p.builtin_pkg && p.mod != typ.mod {
}
@ -1582,7 +1582,7 @@ fn (p mut Parser) dot(str_typ string, method_ph int) string {
// Don't allow `str.len = 0`
if field.access_mod == .public && !p.builtin_pkg && p.mod != typ.mod {
if !field.is_mut && !p.pref.translated && modifying {
p.error('cannot modify public imkey_mut field `$field_name` (type `$typ.name`)')
p.error('cannot modify public immutable field `$field_name` (type `$typ.name`)')
}
}
p.gen(dot + field_name)
@ -1725,7 +1725,7 @@ fn (p mut Parser) index_expr(typ string, fn_ph int) string {
p.tok == .or_assign || p.tok == .and_assign || p.tok == .righ_shift_assign ||
p.tok == .left_shift_assign {
if is_indexer && is_str && !p.builtin_pkg {
p.error('strings are imkey_mut')
p.error('strings are immutable')
}
assign_pos := p.cgen.cur_line.len
p.assigned_type = typ
@ -1822,7 +1822,7 @@ fn (p mut Parser) expression() string {
p.gen(', (')
// Imkey_mut? Can we push?
if !p.expr_var.is_mut && !p.pref.translated {
p.error('`$p.expr_var.name` is imkey_mut (can\'t <<)')
p.error('`$p.expr_var.name` is immutable (can\'t <<)')
}
expr_type := p.expression()
// Two arrays of the same type?