Skip to content

Commit

Permalink
Merge branch 'main' into rivet_fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Dec 4, 2023
2 parents dc2bd05 + 3e1ed10 commit cf85fb5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/rivet/src/ast/Expr.ri
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ pub enum Expr < traits.Stringable {
.StringLiteral as string_lit -> string_lit.pos,
.EnumLiteral as enum_lit -> enum_lit.pos,
.TupleLiteral as tuple_lit -> tuple_lit.pos,
.DynArrayLiteral as vec_lit -> vec_lit.pos,
.DynArrayLiteral as dyn_array_lit -> dyn_array_lit.pos,
.Index as index -> index.pos,
.Selector as selector -> selector.pos,
.Indirect as indirect -> indirect.pos,
Expand Down
22 changes: 11 additions & 11 deletions lib/rivet/src/checker/exprs.ri
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extend Checker {
enum_lit.type
},
.TupleLiteral as mut tuple_lit -> self.check_tuple_literal(tuple_lit),
.DynArrayLiteral as mut vec_lit -> self.check_dyn_array_literal(vec_lit),
.DynArrayLiteral as mut dyn_array_lit -> self.check_dyn_array_literal(dyn_array_lit),
.Ident as ident -> {
ident.type = if ident.name == "_" {
.Void()
Expand Down Expand Up @@ -249,7 +249,7 @@ extend Checker {
return tuple_lit.type;
}

func check_dyn_array_literal(mut self, mut vec_lit: ast.Expr.DynArrayLiteral) -> ast.Type {
func check_dyn_array_literal(mut self, mut dyn_array_lit: ast.Expr.DynArrayLiteral) -> ast.Type {
old_expected_type := self.expected_type;
mut size: uint := 0;
mut is_mut := false;
Expand All @@ -271,15 +271,15 @@ extend Checker {
if has_expected_type {
value_type = self.table.comptime_number_to_type(value_type);
}
for i, mut value in vec_lit.values {
for i, mut value in dyn_array_lit.values {
type := self.check_expr(value);
if i == 0 and !has_expected_type {
value_type = self.table.comptime_number_to_type(type);
self.expected_type = value_type;
} else {
self.check_types(type, value_type) catch |err| {
mut err_b := report.error_builder(err.to_string(), value.position());
err_b.add_note(if vec_lit.is_arr {
err_b.add_note(if dyn_array_lit.is_arr {
"in element {} of array literal"
} else {
"in element {} of dynamic array literal"
Expand All @@ -289,23 +289,23 @@ extend Checker {
}
}
self.expected_type = old_expected_type;
vec_lit.type = if vec_lit.is_arr {
arr_len := if vec_lit.values.len > 0 {
vec_lit.values.len
dyn_array_lit.type = if dyn_array_lit.is_arr {
arr_len := if dyn_array_lit.values.len > 0 {
dyn_array_lit.values.len
} else {
if !has_expected_type {
report.error("could not infer type and size of array", vec_lit.pos);
report.error("could not infer type and size of array", dyn_array_lit.pos);
}
size
};
.Basic(
self.table.universe.add_or_get_array(value_type, arr_len, is_mut),
pos: vec_lit.pos
pos: dyn_array_lit.pos
)
} else {
.Basic(self.table.universe.add_or_get_dyn_array(value_type, is_mut), pos: vec_lit.pos)
.Basic(self.table.universe.add_or_get_dyn_array(value_type, is_mut), pos: dyn_array_lit.pos)
};
return vec_lit.type;
return dyn_array_lit.type;
}

func check_selector(mut self, mut selector: ast.Expr.Selector) -> ast.Type {
Expand Down

0 comments on commit cf85fb5

Please sign in to comment.