Skip to content

Commit 2807103

Browse files
authored
Add better error messages for true, TRUE, false, FALSE, null and Null (#1242)
1 parent eb18f23 commit 2807103

File tree

7 files changed

+24
-0
lines changed

7 files changed

+24
-0
lines changed

compiler/typecheck/step3_function_and_method_bodies.jou

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,12 @@ def typecheck_expression(state: State*, expr: AstExpression*, type_hint: Type*)
12471247
strcat(msg, ", try 'get_stdout()' from \"stdlib/io.jou\"")
12481248
case "stderr":
12491249
strcat(msg, ", try 'get_stderr()' from \"stdlib/io.jou\"")
1250+
case "Null" | "null":
1251+
strcat(msg, ", try NULL")
1252+
case "TRUE" | "true":
1253+
strcat(msg, ", try True")
1254+
case "FALSE" | "false":
1255+
strcat(msg, ", try False")
12501256
fail(expr.location, msg)
12511257
name = expr.varname
12521258
expr.kind = AstExpressionKind.GetFuncPtr

tests/404/false_lowercase.jou

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def blah() -> None:
2+
if false: # Error: no variable named 'false', try False
3+
pass

tests/404/false_uppercase.jou

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def blah() -> None:
2+
if FALSE: # Error: no variable named 'FALSE', try False
3+
pass

tests/404/null_capitalized.jou

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def blah() -> None:
2+
if "hi" == Null: # Error: no variable named 'Null', try NULL
3+
pass

tests/404/null_lowercase.jou

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def blah() -> None:
2+
if "hi" == null: # Error: no variable named 'null', try NULL
3+
pass

tests/404/true_lowercase.jou

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def blah() -> None:
2+
if true: # Error: no variable named 'true', try True
3+
pass

tests/404/true_uppercase.jou

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def blah() -> None:
2+
if TRUE: # Error: no variable named 'TRUE', try True
3+
pass

0 commit comments

Comments
 (0)