Skip to content

Commit

Permalink
[error] Check "throws" for "throw" statements.
Browse files Browse the repository at this point in the history
Close #37
  • Loading branch information
pfusik committed Oct 18, 2021
1 parent 9b5bec5 commit 68b009b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CiResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,8 @@ public override void Visit(CiSwitch statement)

public override void Visit(CiThrow statement)
{
if (!this.CurrentMethod.Throws)
throw StatementException(statement, "'throw' in a method not marked 'throws'");
statement.Message = Resolve(statement.Message);
if (!(statement.Message.Type is CiStringType))
throw StatementException(statement, "The argument of 'throw' must be a string");
Expand Down
12 changes: 12 additions & 0 deletions test/error/StThrowNoThrows.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public static class Test
{
static void Foo()
{
throw "Exception"; //ERROR: 'throw' in a method not marked 'throws'
}

public static bool Run()
{
return true;
}
}
7 changes: 6 additions & 1 deletion test/error/StThrowNonString.ci
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
public static class Test
{
public static bool Run()
static void Foo() throws
{
throw new Test(); //ERROR: The argument of 'throw' must be a string
}

public static bool Run()
{
return true;
}
}
3 changes: 2 additions & 1 deletion test/error/TypeStringSize.ci
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ public static class Test
{
public static bool Run()
{
throw new Test(); //ERROR: The argument of 'throw' must be a string
string(5) s = "foo"; //ERROR: Expected empty parentheses for storage type
return true;
}
}

0 comments on commit 68b009b

Please sign in to comment.