Skip to content

Commit

Permalink
fix mut
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Jan 19, 2024
1 parent 6bdfe90 commit a7342ed
Show file tree
Hide file tree
Showing 23 changed files with 78 additions and 78 deletions.
2 changes: 1 addition & 1 deletion lib/rivet/src/ast/Attributes.ri
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct Attribute {
pub struct Attributes {
pub mut attributes: []Attribute;

pub func add(mut self, attribute: Attribute) -> ! {
pub func add(&mut self, attribute: Attribute) -> ! {
if self.has(attribute.name) {
throw AttributeDuplicatedError(attribute.name);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/rivet/src/builder/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub struct Builder {
}

func import_modules_from_decls(
mut self, sf: ^mut ast.SourceFile, decls: []^mut ast.Decl
&mut self, sf: ^mut ast.SourceFile, decls: []^mut ast.Decl
) -> ! {
for decl in decls {
if decl is .Import(&mut import_decl) {
Expand Down Expand Up @@ -181,7 +181,7 @@ pub struct Builder {
}

func load_module(
mut self, path: string, alias_name: string, file_path: string, pos: token.Pos
&mut self, path: string, alias_name: string, file_path: string, pos: token.Pos
) -> !ast.ImportedMod {
mut mod := self.load_module_files(alias_name, path, file_path)!;
if mod.found {
Expand Down
4 changes: 2 additions & 2 deletions lib/rivet/src/checker/builtin_call.ri
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ extend Checker {
b_func_args_len, builtin_call.args.len
);
if builtin_call.args.len < b_func_args_len {
err := report.error_builder(
mut err := report.error_builder(
"too few arguments to builtin function `{}`".fmt(builtin_call.name),
builtin_call.pos
);
err.add_note(expr_msg);
err.emit();
} else if builtin_call.args.len > b_func.args.len {
err := report.error_builder(
mut err := report.error_builder(
"too many arguments to builtin function `{}`".fmt(builtin_call.name),
builtin_call.pos
);
Expand Down
16 changes: 8 additions & 8 deletions lib/rivet/src/checker/call_expr.ri
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extend Checker {
// call methods
selector.left_type = self.check_expr(selector.left);
if selector.left_type is .Option {
err := report.error_builder(
mut err := report.error_builder(
"option value cannot be called directly", selector.left.position()
);
err.add_help("use the option-check syntax: `foo?.method()` or use `??`: `(foo ?? 5).method()`");
Expand All @@ -95,7 +95,7 @@ extend Checker {
selector.field_type = field.type;
self.check_func_call(f_func.symbol(), call_expr);
} else {
err := report.error_builder(
mut err := report.error_builder(
"type `{}` has no method `{}`".fmt(
left_sym.name, selector.field_name
), selector.field_pos
Expand Down Expand Up @@ -143,7 +143,7 @@ extend Checker {
if call_expr.err_handler.is_propagate {
if !(self.cur_func.is_main || self.inside_test || self.inside_var_decl
|| self.cur_func.ret_type is .Result) {
err := report.error_builder(
mut err := report.error_builder(
"cannot propagate the result value", call_expr.err_handler.pos
);
err.add_note(
Expand Down Expand Up @@ -175,7 +175,7 @@ extend Checker {
);
}
} else if call_expr.type is .Result && !self.inside_guard_expr {
err := report.error_builder(
mut err := report.error_builder(
"{} `{}` returns a result".fmt(
call_expr.func_.type_of(), call_expr.func_.name
), call_expr.pos
Expand Down Expand Up @@ -277,7 +277,7 @@ extend Checker {
if !call_expr.has_named_args() {
expr_args_len := call_expr.args.len;
if expr_args_len > type_fields.len {
err := report.error_builder(
mut err := report.error_builder(
"too many arguments to {} `{}`".fmt(
type_sym.type_of(), type_sym.name
), call_expr.pos
Expand Down Expand Up @@ -318,7 +318,7 @@ extend Checker {
if call_expr.has_spread_expr {
spread_expr_t := self.check_expr(call_expr.spread_expr);
if spread_expr_t != call_expr.type {
err := report.error_builder(
mut err := report.error_builder(
"expected type `{}`, found `{}`".fmt(
call_expr.type, spread_expr_t
), call_expr.spread_expr.position()
Expand Down Expand Up @@ -445,13 +445,13 @@ extend Checker {
if expr_args_len != func_args_len {
expr_msg := "expected {} argument(s), found {}".fmt(func_args_len, expr_args_len);
if expr_args_len < func_args_len {
err := report.error_builder(
mut err := report.error_builder(
"too few arguments to {} `{}`".fmt(kind, func_.name), call_expr.pos
);
err.add_note(expr_msg);
err.emit();
} else if !func_.is_variadic {
err := report.error_builder(
mut err := report.error_builder(
"too many arguments to {} `{}`".fmt(kind, func_.name), call_expr.pos
);
err.add_note(expr_msg);
Expand Down
8 changes: 4 additions & 4 deletions lib/rivet/src/checker/decls.ri
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ extend Checker {
}
}
if func_decl.ret_type is .Pointer && func_decl.abi != .Rivet {
err := report.error_builder(
mut err := report.error_builder(
"function `{}` should return an optional pointer".fmt(func_decl.name),
func_decl.ret_type.position()
);
Expand Down Expand Up @@ -276,7 +276,7 @@ extend Checker {
);
}
} else {
err := report.error_builder(
mut err := report.error_builder(
"`never` functions cannot return",
func_decl.pos
);
Expand All @@ -285,7 +285,7 @@ extend Checker {
}
},
else -> {
err := report.error_builder(
mut err := report.error_builder(
"`never` functions cannot return",
func_decl.pos
);
Expand All @@ -294,7 +294,7 @@ extend Checker {
}
}
} else {
err := report.error_builder(
mut err := report.error_builder(
"`never` functions cannot be empty",
func_decl.pos
);
Expand Down
38 changes: 19 additions & 19 deletions lib/rivet/src/checker/exprs.ri
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extend Checker {
if enum_info.is_tagged && !enum_lit.from_is_cmp
&& !enum_lit.is_instance {
if variant.has_type {
err := report.error_builder(
mut err := report.error_builder(
"variant `{}` cannot be initialized without arguments".fmt(
enum_lit.value
),
Expand Down Expand Up @@ -176,7 +176,7 @@ extend Checker {
ast.Var(var_sym) -> var_sym.type,
ast.Func(mut func_sym) -> {
if func_sym.abi != .Rivet {
err := report.error_builder(
mut err := report.error_builder(
"cannot use an extern function as a value", ident.pos
);
err.add_help("wrap the extern function with a function");
Expand All @@ -200,7 +200,7 @@ extend Checker {
indirect.is_mut = indirect.left_type.is_pointer();
indirect.left_type.ptr_inner()
} else {
err := report.error_builder(
mut err := report.error_builder(
"invalid indirect for `{}`".fmt(indirect.left_type), indirect.pos
);
if indirect.left_type is .Rawptr {
Expand Down Expand Up @@ -396,7 +396,7 @@ extend Checker {
if selector.left_sym is ast.TypeSym(mut type_sym) {
if type_sym.info is .Enum(enum_info) {
if variant := enum_info.get_variant(selector.field_name); variant.has_type {
err := report.error_builder(
mut err := report.error_builder(
"variant `{}` cannot be initialized without arguments".fmt(
selector.field_name
),
Expand Down Expand Up @@ -426,7 +426,7 @@ extend Checker {
ast.Const(const_sym) -> const_sym.type,
ast.Var(var_sym) -> var_sym.type,
else -> {
err := report.error_builder(
mut err := report.error_builder(
"unexpected bug for selector expression", selector.pos
);
err.add_note("please report this bug, thanks =D");
Expand All @@ -445,15 +445,15 @@ extend Checker {
} else if sym := left_sym.scope.find(selector.field_name) {
if sym is ast.Func(mut func_sym) {
if func_sym.is_method {
err := report.error_builder(
mut err := report.error_builder(
"cannot take value of method `{}`".fmt(selector.field_name),
selector.field_pos
);
err.add_help("use parentheses to call the method");
err.emit();
^mut .Void
} else {
err := report.error_builder(
mut err := report.error_builder(
"cannot take value of associated function `{}`".fmt(
selector.field_name
), selector.field_pos
Expand All @@ -473,7 +473,7 @@ extend Checker {
^mut .Void
}
} else {
err := report.error_builder(
mut err := report.error_builder(
"type `{}` has no field `{}`".fmt(
left_sym.name, selector.field_name
), selector.field_pos
Expand Down Expand Up @@ -529,7 +529,7 @@ extend Checker {
},
else -> {
if !(index.left_type is .Pointer || index.left_type == self.env.string_t) {
err := report.error_builder(
mut err := report.error_builder(
"type `{}` does not support indexing".fmt(index.left_type),
index.pos
);
Expand All @@ -549,7 +549,7 @@ extend Checker {
}
if index.left_type == self.env.string_t {
if index.index is .Range {
err := report.error_builder(
mut err := report.error_builder(
"`string` does not support slicing syntax", index.pos
);
err.add_help("use `.substr()` instead");
Expand All @@ -574,7 +574,7 @@ extend Checker {
"operator `~` can only be used with numeric values", unary.pos
),
.Minus -> if self.env.is_unsigned_int(unary.type) {
err := report.error_builder(
mut err := report.error_builder(
"cannot apply unary operator `-` to type `{expr.typ}`".fmt(
unary.type
), unary.pos
Expand Down Expand Up @@ -635,7 +635,7 @@ extend Checker {

if binary.op in [.Plus, .Minus, .Mul, .Div, .Mod, .Xor, .Amp, .Pipe] {
if left_type.is_pointer() {
err := report.error_builder(
mut err := report.error_builder(
"pointer arithmetic is not allowed", binary.pos
);
if binary.op == .Plus {
Expand Down Expand Up @@ -690,7 +690,7 @@ extend Checker {
if left_type is .Option(opt) {
if !self.check_compatible_types(right_type, opt.inner)
&& right_type !is .Never {
err := report.error_builder(
mut err := report.error_builder(
"expected type `{}`, found `{}`".fmt(opt.inner, right_type),
binary.right.position()
);
Expand Down Expand Up @@ -719,7 +719,7 @@ extend Checker {
|| !(left_sym.info is .Enum(enum_info)
&& enum_info.is_tagged))
&& !left_sym.has_method(op_method) {
err := report.error_builder(
mut err := report.error_builder(
"cannot use operator `{}` with type `{}`".fmt(
binary.op, left_sym.name
), binary.pos
Expand Down Expand Up @@ -820,7 +820,7 @@ extend Checker {
} else if binary.left is .Binary(bin_left) {
if bin_left.op != binary.op && bin_left.op in [.LogicalAnd, .LogicalOr] {
// use `(a && b) || c` instead of `a && b || c`
err := report.error_builder(
mut err := report.error_builder(
"ambiguous boolean expression", binary.pos
);
err.add_help(
Expand Down Expand Up @@ -928,7 +928,7 @@ extend Checker {
expr_type := self.check_expr(return_expr.expr);
self.expected_type = old_expected_type;
self.check_types(expr_type, self.cur_func.ret_type) catch |err| {
err_b := report.error_builder(
mut err_b := report.error_builder(
err.to_string(), return_expr.expr.position()
);
err_b.add_note(
Expand All @@ -942,7 +942,7 @@ extend Checker {
self.cur_func.ret_type is .Void
|| (self.cur_func.ret_type is .Result(res_t) && res_t.inner is .Void)
) {
err := report.error_builder(
mut err := report.error_builder(
"expected `{}` value in return argument".fmt(self.cur_func.ret_type),
return_expr.pos
);
Expand All @@ -966,7 +966,7 @@ extend Checker {
if !(expr_sym == self.env.throwable_sym
|| expr_sym.implement_trait(self.env.throwable_sym)
) {
err_b := report.error_builder(
mut err_b := report.error_builder(
"using an invalid value as an error to throw",
throw_expr.expr.position()
);
Expand All @@ -980,7 +980,7 @@ extend Checker {
err_b.emit();
}
} else {
err_b := report.error_builder(
mut err_b := report.error_builder(
"{} `{}` cannot throws errors".fmt(
self.cur_func.kind(), self.cur_func.name
), throw_expr.expr.position()
Expand Down
4 changes: 2 additions & 2 deletions lib/rivet/src/checker/match_expr.ri
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extend Checker {
} else {
if match_expr.is_typematch && !(expr_sym.info is .Enum
|| expr_sym.info is .Trait) {
err := report.error_builder(
mut err := report.error_builder(
"invalid type for type-match", match_expr.expr.position()
);
err.add_note("expected trait value, found `{}`", expr_type);
Expand Down Expand Up @@ -203,7 +203,7 @@ extend Checker {
return match_expr.expected_type;
}

err := report.error_builder("`match` must be exhaustive", match_expr.pos);
mut err := report.error_builder("`match` must be exhaustive", match_expr.pos);
if unhandled.len > 0 {
mut err_details := "add `match` branches for: ";
if unhandled.len < MATCH_EXHAUSTIVE_CUTOFF_LIMIT {
Expand Down
6 changes: 3 additions & 3 deletions lib/rivet/src/checker/mutability.ri
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ extend Checker {
if var_info.is_mut {
var_info.is_changed = true;
} else {
err := if var_info.level == .Argument {
err_b := report.error_builder(
mut err := if var_info.level == .Argument {
mut err_b := report.error_builder(
"cannot use variable `{}` as mutable argument".fmt(sym.name), pos
);
err_b.add_help(
"consider making this argument mutable: `mut {}`", var_info.name
);
err_b
} else {
err_b := report.error_builder(
mut err_b := report.error_builder(
"cannot use variable `{}` as mutable value".fmt(sym.name), pos
);
err_b.add_help(
Expand Down
2 changes: 1 addition & 1 deletion lib/rivet/src/checker/stmts.ri
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extend Checker {
}
self.check_stmt(for_stmt.stmt);
} else {
err := report.error_builder(
mut err := report.error_builder(
"`{}` is not an iterable type".fmt(iterable_t),
for_stmt.iterable.position()
);
Expand Down
4 changes: 2 additions & 2 deletions lib/rivet/src/checker/trait_impl.ri
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extend Checker {
));
}
if errors.len > 0 {
err := report.error_builder(
mut err := report.error_builder(
"type `{}` incorrectly implements method `{}` of trait `{}`".fmt(
impltor.qualname(), impl.name, trait_sym.qualname()
), impl.pos
Expand Down Expand Up @@ -73,7 +73,7 @@ extend Checker {
}
}
if impl_does_not_implemented.len > 0 {
err := report.error_builder(
mut err := report.error_builder(
"type `{}` does not implement trait `{}`".fmt(
impltor.qualname(), trait_sym.qualname()
), pos
Expand Down
Loading

0 comments on commit a7342ed

Please sign in to comment.