From 47a1258648df31a50a230c864c31c48e4b0b7f63 Mon Sep 17 00:00:00 2001 From: Louis Gesbert Date: Wed, 26 Oct 2022 11:09:15 +0200 Subject: [PATCH] Fix error handling of invalid subscope variable assignments --- compiler/surface/name_resolution.ml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/compiler/surface/name_resolution.ml b/compiler/surface/name_resolution.ml index e6c3ed35..3a83c7e2 100644 --- a/compiler/surface/name_resolution.ml +++ b/compiler/surface/name_resolution.ml @@ -671,10 +671,16 @@ let get_def_key | [y; x] -> let (subscope_uid, subscope_real_uid) : SubScopeName.t * ScopeName.t = match - Desugared.Ast.IdentMap.find (Marked.unmark y) scope_ctxt.var_idmap + Desugared.Ast.IdentMap.find_opt (Marked.unmark y) scope_ctxt.var_idmap with - | SubScope (v, u) -> v, u - | _ -> invalid_arg "subscope_real_uid" + | Some (SubScope (v, u)) -> v, u + | Some _ -> + Errors.raise_spanned_error pos + "Invalid access to input variable, '%s' is not a subscope" + (Marked.unmark y) + | None -> + Errors.raise_spanned_error pos "No definition found for subscope '%s'" + (Marked.unmark y) in let x_uid = get_var_uid subscope_real_uid ctxt x in Desugared.Ast.ScopeDef.SubScopeVar (subscope_uid, x_uid, pos)