diff --git a/CiResolver.cs b/CiResolver.cs index 464d1bab..cb84c901 100644 --- a/CiResolver.cs +++ b/CiResolver.cs @@ -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"); diff --git a/test/error/StThrowNoThrows.ci b/test/error/StThrowNoThrows.ci new file mode 100644 index 00000000..ef722e44 --- /dev/null +++ b/test/error/StThrowNoThrows.ci @@ -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; + } +} diff --git a/test/error/StThrowNonString.ci b/test/error/StThrowNonString.ci index b90577ae..9d255b8d 100644 --- a/test/error/StThrowNonString.ci +++ b/test/error/StThrowNonString.ci @@ -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; + } } diff --git a/test/error/TypeStringSize.ci b/test/error/TypeStringSize.ci index b90577ae..b3271466 100644 --- a/test/error/TypeStringSize.ci +++ b/test/error/TypeStringSize.ci @@ -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; } }