From c730ec5583cdd9ff6900ede2dc71e08ca4d81c46 Mon Sep 17 00:00:00 2001 From: Benjamin Peinhardt Date: Mon, 16 Dec 2024 01:47:53 -0600 Subject: [PATCH] update error --- priv/static/squared_away.mjs | 23 +++++++++++++------ .../squared_away_lang/typechecker.gleam | 9 ++++++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/priv/static/squared_away.mjs b/priv/static/squared_away.mjs index 8cdb288..dc63ef0 100644 --- a/priv/static/squared_away.mjs +++ b/priv/static/squared_away.mjs @@ -7523,7 +7523,7 @@ function typecheck(env, expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/typechecker", - 20, + 21, "typecheck", "Pattern match failed, no pattern matched the value.", { value: key } @@ -7587,7 +7587,7 @@ function typecheck(env, expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/typechecker", - 58, + 59, "", "Pattern match failed, no pattern matched the value.", { value: i } @@ -7620,7 +7620,7 @@ function typecheck(env, expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/typechecker", - 75, + 76, "", "Pattern match failed, no pattern matched the value.", { value: t2 } @@ -7670,7 +7670,7 @@ function typecheck(env, expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/typechecker", - 95, + 96, "typecheck", "Pattern match failed, no pattern matched the value.", { value: key } @@ -7734,7 +7734,7 @@ function typecheck(env, expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/typechecker", - 133, + 134, "", "Pattern match failed, no pattern matched the value.", { value: i } @@ -7767,7 +7767,7 @@ function typecheck(env, expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/typechecker", - 150, + 151, "", "Pattern match failed, no pattern matched the value.", { value: t2 } @@ -7829,7 +7829,7 @@ function typecheck(env, expr) { return new Ok(new LabelDef2(new TDoNotEvaluate(), txt)); } else { return new Error( - new TypeError2(new TypeError("Duplicate Label")) + new TypeError2(new TypeError("Duplicate Label!!!")) ); } } else if (expr instanceof Label) { @@ -7878,6 +7878,15 @@ function typecheck(env, expr) { new TypeError("Label points to itself") ) ); + } else if (x.isOk() && x[0] instanceof LabelDef) { + let ldtxt = x[0].txt; + return new Error( + new TypeError2( + new TypeError( + "Label points to another label definition, cannot be used as a standalone label. Did you mean to use a cross_label?" + ) + ) + ); } else { let expr$1 = x[0]; let $ = typecheck(env, expr$1); diff --git a/src/squared_away/squared_away_lang/typechecker.gleam b/src/squared_away/squared_away_lang/typechecker.gleam index 50af7b8..91bb95c 100644 --- a/src/squared_away/squared_away_lang/typechecker.gleam +++ b/src/squared_away/squared_away_lang/typechecker.gleam @@ -3,6 +3,7 @@ import gleam/int import gleam/list.{Continue, Stop} import gleam/option.{None, Some} import gleam/result +import gleam/io import squared_away/squared_away_lang/error import squared_away/squared_away_lang/grid import squared_away/squared_away_lang/parser/expr @@ -167,7 +168,6 @@ pub fn typecheck( } } expr.LabelDef(txt) -> { - // A Label Definition pointing at a label definition is an error // Duplicate label definitions should be a type error let defs = @@ -181,7 +181,7 @@ pub fn typecheck( case defs { // A LabelDefinition should not be referenced in a formula. 0 -> Ok(typed_expr.LabelDef(typ.TDoNotEvaluate, txt)) - _ -> Error(error.TypeError(type_error.TypeError("Duplicate Label"))) + _ -> Error(error.TypeError(type_error.TypeError("Duplicate Label!!!"))) } } expr.Label(txt) -> { @@ -216,6 +216,11 @@ pub fn typecheck( error.TypeError(type_error.TypeError("Label points to itself")), ) } + Ok(expr.LabelDef(ldtxt)) -> { + Error( + error.TypeError(type_error.TypeError("Label points to another label definition, cannot be used as a standalone label. Did you mean to use a cross_label?")) + ) + } Ok(expr) -> { case typecheck(env, expr) { Ok(te) -> Ok(typed_expr.Label(type_: te.type_, key:, txt:))