Skip to content

Commit

Permalink
update error
Browse files Browse the repository at this point in the history
  • Loading branch information
bcpeinhardt committed Dec 16, 2024
1 parent 73ab604 commit c730ec5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
23 changes: 16 additions & 7 deletions priv/static/squared_away.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions src/squared_away/squared_away_lang/typechecker.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand All @@ -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) -> {
Expand Down Expand Up @@ -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:))
Expand Down

0 comments on commit c730ec5

Please sign in to comment.