Skip to content

Commit

Permalink
Adds error message when calling a named instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
modlfo committed Mar 5, 2023
1 parent e1e043f commit dfdd25f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/core/inference.ml
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,12 @@ let rec addContextArg (env : Env.in_func) instance (f : Env.f) args loc =
let t = C.path loc fpath in
let e = { e = EId context_name; t; loc } in
env, e :: args
| 0, Some _ -> failwith "cannot call other instance of the same type"
| 0, Some _ ->
let msg =
Pla.print
[%pla {|This function belongs to the same instance and it must not be called on a different instance.|}]
in
Error.raiseError msg loc
(* no instance name provided *)
| _, None ->
let number =
Expand All @@ -520,6 +525,7 @@ let rec addContextArg (env : Env.in_func) instance (f : Env.f) args loc =
let env = Env.addVar env unify name t Inst loc in
let e = { e = EMember ({ e = EId context_name; t = ctx_t; loc }, name); loc; t } in
env, e :: args
(* array of instances *)
| _, Some (name, Some index) ->
let env, index = exp env index in
unifyRaise index.loc (C.int ~loc:Loc.default) index.t;
Expand Down
10 changes: 10 additions & 0 deletions test/errors/error40.vult
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fun reset() {
mem x = 0;
}
and counter() {
mem x = x + 1;
if (x > 10) {
foo:reset();
}
return x;
}

0 comments on commit dfdd25f

Please sign in to comment.