Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java

Issue 9185013: Issue 965: Report error for static local function (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java b/compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java
index 25c21ab8337251b62ce413bb1a390baf23970fb4..b4e869b91fcb4051666eebb7de10327fa050c584 100644
--- a/compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java
+++ b/compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java
@@ -395,4 +395,43 @@ public class NegativeParserTest extends CompilerTestCase {
"}"),
errEx(ParserErrorCode.INTERFACE_METHOD_WITH_BODY, 3, 3, 3));
}
+
+ /**
+ * The Language Specification in the section 6.1 states: "It is a compile-time error to preface a
+ * function declaration with the built-in identifier static."
+ */
+ public void test_staticFunction_topLevel() {
+ parseExpectErrors(
+ Joiner.on("\n").join(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "static foo() {",
+ "}"),
+ errEx(ParserErrorCode.TOP_LEVEL_CANNOT_BE_STATIC, 2, 1, 6));
+ }
+
+ /**
+ * The Language Specification in the section 6.1 states: "It is a compile-time error to preface a
+ * function declaration with the built-in identifier static."
+ */
+ public void test_staticFunction_local() {
+ DartParserRunner parserRunner =
+ parseExpectErrors(
+ Joiner.on("\n").join(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "topLevelMethodWithLongEnoughNameToForceWrapping() {",
+ " static int localFunction() {",
+ " }",
+ "}"),
+ errEx(ParserErrorCode.LOCAL_CANNOT_BE_STATIC, 3, 3, 6));
+ // Check that "static" was ignored and "int" parsed as return type.
+ assertEquals(
+ makeCode(
+ "// unit " + getName(),
+ "",
+ "topLevelMethodWithLongEnoughNameToForceWrapping() {",
+ " int localFunction() {",
+ " };",
+ "}"),
+ parserRunner.getDartUnit().toSource());
+ }
}

Powered by Google App Engine
This is Rietveld 408576698