Make assert a reserved word

Issue 5051.

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@12861 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
hausner@google.com
2012-09-25 17:59:35 +00:00
parent 9f5c839876
commit ffedcb612d
8 changed files with 14 additions and 260 deletions
+1 -12
View File
@@ -6296,16 +6296,6 @@ AstNode* Parser::ParseJump(String* label_name) {
}
bool Parser::IsDefinedInLexicalScope(const String& ident) {
if (ResolveIdentInLocalScope(TokenPos(), ident, NULL)) {
return true;
}
Object& obj = Object::Handle();
obj = library_.LookupObject(ident);
return !obj.IsNull();
}
AstNode* Parser::ParseStatement() {
TRACE_PARSER("ParseStatement");
AstNode* statement = NULL;
@@ -6350,8 +6340,7 @@ AstNode* Parser::ParseStatement() {
ExpectSemicolon();
} else if (CurrentToken() == Token::kIF) {
statement = ParseIfStatement(label_name);
} else if ((CurrentToken() == Token::kASSERT) &&
!IsDefinedInLexicalScope(*CurrentLiteral())) {
} else if (CurrentToken() == Token::kASSERT) {
statement = ParseAssertStatement();
ExpectSemicolon();
} else if (IsVariableDeclaration()) {
-1
View File
@@ -498,7 +498,6 @@ class Parser : public ValueObject {
RawClass* TypeParametersScopeClass() const;
const Type* ReceiverType(intptr_t type_pos) const;
bool IsInstantiatorRequired() const;
bool IsDefinedInLexicalScope(const String& ident);
bool ResolveIdentInLocalScope(intptr_t ident_pos,
const String &ident,
AstNode** node);
+1 -1
View File
@@ -143,7 +143,7 @@ namespace dart {
// to update kFirstKeyword and kLastKeyword below.
#define DART_KEYWORD_LIST(KW) \
KW(kABSTRACT, "abstract", 0, kPseudoKeyword) /* == kFirstKeyword */ \
KW(kASSERT, "assert", 0, kPseudoKeyword) \
KW(kASSERT, "assert", 0, kKeyword) \
KW(kBREAK, "break", 0, kKeyword) \
KW(kCASE, "case", 0, kKeyword) \
KW(kCATCH, "catch", 0, kKeyword) \
+12
View File
@@ -210,6 +210,18 @@ Language/14_Types/5_Function_Types_A02_t01: Fail # TODO(vm-team): Please triage
LibTest/core/double/INFINITY_A01_t02: Fail # TODO(vm-team): Please triage this failure.
LibTest/core/double/NEGATIVE_INFINITY_A01_t02: Fail # TODO(vm-team): Please triage this failure.
# Failures related to assert being a reserved word now. co19 issue 218.
Language/10_Expressions/28_Identifier_Reference_A02_t01: Fail, OK
Language/10_Expressions/28_Identifier_Reference_A04_t07: Fail, OK
Language/10_Expressions/28_Identifier_Reference_A08_t04: Fail, OK
Language/10_Expressions/28_Identifier_Reference_A08_t05: Fail, OK
Language/10_Expressions/28_Identifier_Reference_A08_t38: Fail, OK
Language/11_Statements/15_Assert_A05_t01: Fail, OK
Language/11_Statements/15_Assert_A05_t02: Fail, OK
Language/11_Statements/15_Assert_A05_t03: Fail, OK
Language/11_Statements/15_Assert_A05_t04: Fail, OK
Language/11_Statements/15_Assert_A05_t05: Fail, OK
LibTest/core/Completer/completeException_A02_t01: Fail # co19 issue 224
LibTest/core/int/operator_left_shift_A01_t03: Fail # co19 issue 224
LibTest/core/int/operator_right_shift_A01_t03: Fail # co19 issue 224
@@ -1,16 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
class AssertKeywordNegativeTest {
static void testMain() {
assert(true);
"assert"(true);
}
}
main() {
AssertKeywordNegativeTest.testMain();
}
@@ -1,225 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/** A function that accepts 0..2 arguments and records calls. */
void poly([a, b]) {
polyCount++;
polyArg = a;
}
/** First argument of most recent call to [poly]. */
var polyArg = 0;
/** Number of calls to [poly]. */
var polyCount = 0;
// Four (Super)classes that declare an "assert" member.
class SuperGet {
/** Declare "assert" as a getter. */
get assert => poly;
/**
* A method that shold see an 'assert' declaration in scope and not
* not act as an assertion.
*/
void lexicalAssert(x) {
assert(x);
}
}
class SuperMethod {
/** Declare "assert" as a method. */
assert([a, b]) => poly(a, b);
void lexicalAssert(x) {
assert(x);
}
}
class SuperField {
/** Declare "assert" as a field. */
var assert;
SuperField() : assert = poly;
void lexicalAssert(x) {
assert(x);
}
}
class SuperNon {
/** Implementation of "assert" calls on this. */
noSuchMethod(x, y) {
switch (y.length) {
case 0: return poly();
case 1: return poly(y[0]);
case 2: return poly(y[0], y[1]);
}
}
void lexicalAssert(x) {
// Hack, since there is no lexically enclosing 'assert' declaration here,
// so just act as if there was to avoid special casing it in the test.
poly(x);
}
}
// Corresponding sub-classes that read/call "assert" in different ways.
// In every case except "assert(exp);" (in the "assert1" methods) this should
// access the superclass member.
class SubGet extends SuperGet {
/** Read assert as a variable. */
void getAssert(x) {
assert;
}
/** Call "assert" with zero arguments. */
void assert0(x) {
assert();
}
/** Make an actual assertion. */
void assert1(x) {
assert(x);
}
/** Call "assert" with one argument in expression context. */
void assertExp(x) {
var z = assert(x);
}
/** Call "assert" with two arguments. */
void assert2(x) {
assert(x, x);
}
}
class SubMethod extends SuperMethod {
void getAssert(x) {
assert;
}
void assert0(x) {
assert();
}
void assert1(x) {
assert(x);
}
void assertExp(x) {
var z = assert(x);
}
void assert2(x) {
assert(x, x);
}
}
class SubField extends SuperField {
void getAssert(x) {
assert;
}
void assert0(x) {
assert();
}
void assert1(x) {
assert(x);
}
void assertExp(x) {
var z = assert(x);
}
void assert2(x) {
assert(x, x);
}
}
class SubNon extends SuperNon {
void getAssert(x) {
assert;
}
assert0(x) {
assert();
}
void assert1(x) {
assert(x);
}
void assertExp(x) {
var z = assert(x);
}
void assert2(x) {
assert(x, x);
}
}
testAssertDeclared() {
var get = new SubGet();
var method = new SubMethod();
var field = new SubField();
var non = new SubNon();
void expectCallsPoly(code, [bool noArgument = false]) {
int oldPolyCount = polyCount;
int newPolyArg = polyArg + 1;
int expectedPolyArg = noArgument ? null : newPolyArg;
code(newPolyArg);
Expect.equals(oldPolyCount + 1, polyCount);
Expect.equals(expectedPolyArg, polyArg);
if (noArgument) polyArg = newPolyArg;
}
void expectAssert(code) {
int oldPolyCount = polyCount;
// Detect whether asserts are enabled.
bool assertsEnabled = false;
assert(assertsEnabled = true);
try {
code(polyArg + 1);
// If asserts are enabled, we should not get here.
// If they are not, the call does nothing.
if (assertsEnabled) {
Expect.fail("Didn't call assert with asserts enabled.");
}
} on AssertionError catch (e) {
if (!assertsEnabled) Expect.fail("Called assert with asserts disabled?");
}
Expect.equals(oldPolyCount, polyCount);
}
// Sanity check.
expectCallsPoly(poly);
// Doesn't fail to read "assert".
get.getAssert(0);
method.getAssert(0);
field.getAssert(0);
expectCallsPoly(non.getAssert, true); // Hits 'noSuchMethod' for the getter.
// Check when 'assert' is a superclass member declaration (or, simulated with
// noSuchMethod).
void testSuperAssert(object) {
expectCallsPoly(object.assert0, true);
expectAssert(object.assert1);
expectCallsPoly(object.assertExp);
expectCallsPoly(object.assert2);
expectCallsPoly(object.lexicalAssert);
}
testSuperAssert(get);
testSuperAssert(method);
testSuperAssert(field);
testSuperAssert(non);
// A local declaration will inhibit assert-behavior.
expectCallsPoly((x) {
// Declare "assert" as a local variable.
var assert = poly;
assert(x);
});
expectCallsPoly((x) {
// Declare "assert" as a local function.
void assert(x) => poly(x);
assert(x);
});
}
main() {
testAssertDeclared();
}
-4
View File
@@ -30,7 +30,6 @@ pseudo_kw_illegal_test/08: Fail # Issue 356
pseudo_kw_illegal_test/10: Fail # Issue 356
pseudo_kw_illegal_test/14: Fail # Issue 356
assert_lexical_scope_test: Fail # Issue 4935
# These bugs refer currently ongoing language discussions.
constructor5_test: Fail # (Discussion ongoing)
@@ -102,13 +101,11 @@ compile_time_constant_checked3_test/05: Fail, OK
compile_time_constant_checked3_test/06: Fail, OK
[ $compiler == dartc ]
assert_lexical_scope_test: Fail, OK # test issue 5276
implicit_this_test/none: Fail # should not warn about allocating SubAbstract2
metadata_test: Fail
call_constructor_on_unresolvable_class_test/03: Fail, OK # 'library' cannot be used as a prefix because it is a built-in identifier
get_set_syntax_test/none: Fail # does not accept getter/setter with no method body
application_negative_test: Fail # Runtime only test, rewrite as multitest
assert_keyword_negative_test: Fail # Runtime only test, rewrite as multitest
assign_instance_method_negative_test: Fail # Runtime only test, rewrite as multitest
body_less_constructor_wrong_arg_negative_test: Fail # Runtime only test, rewrite as multitest
call_nonexistent_static_test/03: Fail # Unresolved static calls are no longer errors.
@@ -275,7 +272,6 @@ string_escape1_negative_test: Skip
import_combinators_test: Fail
metadata_test: Fail
# Fails in conservative mode, issue 4935, passes in minifinying mode.
assert_lexical_scope_test: Fail, Pass
bad_constructor_test/04: Fail
bad_constructor_test/05: Fail
bad_constructor_test/06: Fail
-1
View File
@@ -12,7 +12,6 @@ class PseudoKWTest {
var abstract = 0;
var as = 0;
var assert = 0;
var call = 0;
var Dynamic = 0;
var factory = 0;