Skip to content

Commit

Permalink
Test all methods in semantic_visitor_test.
Browse files Browse the repository at this point in the history
BUG=
R=karlklose@google.com

Review URL: https://codereview.chromium.org//1152013006
  • Loading branch information
johnniwinther committed Jun 7, 2015
1 parent add5a69 commit deb1697
Show file tree
Hide file tree
Showing 4 changed files with 350 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4078,6 +4078,7 @@ class TraversalSendMixin<R, A> implements SemanticSendVisitor<R, A> {
Selector selector,
Node rhs,
A arg) {
apply(receiver, arg);
apply(rhs, arg);
return null;
}
Expand Down
68 changes: 53 additions & 15 deletions tests/compiler/dart2js/semantic_visitor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,38 +168,52 @@ class Test {
}

const List<VisitKind> UNTESTABLE_KINDS = const <VisitKind>[
// A final field shadowing a non-final field is currently not supported in
// resolution.
VisitKind.VISIT_SUPER_FIELD_FIELD_COMPOUND,
VisitKind.VISIT_SUPER_FIELD_FIELD_PREFIX,
VisitKind.VISIT_SUPER_FIELD_FIELD_POSTFIX,
// Combination of method and setter with the same name is currently not
// supported by the element model.
VisitKind.VISIT_STATIC_METHOD_SETTER_COMPOUND,
VisitKind.VISIT_STATIC_METHOD_SETTER_PREFIX,
VisitKind.VISIT_STATIC_METHOD_SETTER_POSTFIX,
VisitKind.VISIT_TOP_LEVEL_METHOD_SETTER_COMPOUND,
VisitKind.VISIT_TOP_LEVEL_METHOD_SETTER_PREFIX,
VisitKind.VISIT_TOP_LEVEL_METHOD_SETTER_POSTFIX,
VisitKind.VISIT_SUPER_FIELD_FIELD_COMPOUND,
VisitKind.VISIT_SUPER_FIELD_FIELD_PREFIX,
VisitKind.VISIT_SUPER_FIELD_FIELD_POSTFIX,
VisitKind.VISIT_SUPER_METHOD_SETTER_COMPOUND,
VisitKind.VISIT_SUPER_METHOD_SETTER_PREFIX,
VisitKind.VISIT_SUPER_METHOD_SETTER_POSTFIX,
// Invalid use of setters is currently reported through an erroneous element.
VisitKind.VISIT_STATIC_SETTER_INVOKE,
VisitKind.VISIT_STATIC_SETTER_GET,
VisitKind.VISIT_TOP_LEVEL_SETTER_GET,
VisitKind.VISIT_TOP_LEVEL_SETTER_INVOKE,
// The constant expressions of assignment to constant type literals cannot be
// handled the compile constant evaluator.
VisitKind.VISIT_CLASS_TYPE_LITERAL_SET,
VisitKind.VISIT_TYPEDEF_TYPE_LITERAL_SET,
VisitKind.VISIT_TYPE_VARIABLE_TYPE_LITERAL_SET,
VisitKind.VISIT_DYNAMIC_TYPE_LITERAL_SET,
// Invalid assignments is currently report through an erroneous element.
VisitKind.VISIT_TYPE_VARIABLE_TYPE_LITERAL_SET,
VisitKind.VISIT_FINAL_PARAMETER_SET,
VisitKind.VISIT_FINAL_LOCAL_VARIABLE_SET,
VisitKind.VISIT_LOCAL_FUNCTION_SET,
VisitKind.VISIT_STATIC_GETTER_SET,
VisitKind.VISIT_STATIC_SETTER_GET,
VisitKind.VISIT_STATIC_SETTER_INVOKE,
VisitKind.VISIT_FINAL_STATIC_FIELD_SET,
VisitKind.VISIT_STATIC_FUNCTION_SET,
VisitKind.VISIT_FINAL_TOP_LEVEL_FIELD_SET,
VisitKind.VISIT_TOP_LEVEL_GETTER_SET,
VisitKind.VISIT_TOP_LEVEL_SETTER_GET,
VisitKind.VISIT_TOP_LEVEL_SETTER_INVOKE,
VisitKind.VISIT_TOP_LEVEL_FUNCTION_SET,
VisitKind.VISIT_FINAL_SUPER_FIELD_SET,
VisitKind.VISIT_SUPER_GETTER_SET,
VisitKind.VISIT_SUPER_METHOD_SET,
// The only undefined unary, `+`, is currently handled and skipped in the
// parser.
VisitKind.ERROR_UNDEFINED_UNARY_EXPRESSION,
// Constant expression are currently not computed during resolution.
VisitKind.VISIT_CONSTANT_GET,
VisitKind.VISIT_CONSTANT_INVOKE,
];

main(List<String> arguments) {
Expand Down Expand Up @@ -245,7 +259,8 @@ main(List<String> arguments) {
m.simpleName != #apply)
.map((m) => m.simpleName).toSet();
symbols2.removeAll(symbols1);
print("Untested visit methods:\n ${symbols2.join(',\n ')},\n");
Expect.isTrue(symbols2.isEmpty,
"Untested visit methods:\n ${symbols2.join(',\n ')},\n");
}
], (f) => f()));
}
Expand Down Expand Up @@ -281,15 +296,13 @@ Future test(Set<VisitKind> unvisitedKinds,
sourceFiles['main.dart'] = mainSource.toString();

Compiler compiler = compilerFor(sourceFiles,
options: ['--analyze-all', '--analyze-only']);
options: ['--analyze-all',
'--analyze-only',
'--enable-null-aware-operators']);
return compiler.run(Uri.parse('memory:main.dart')).then((_) {
testMap.forEach((String filename, Test test) {
LibraryElement library = compiler.libraryLoader.lookupLibrary(
Uri.parse('memory:$filename'));
var expectedVisits = test.expectedVisits;
if (expectedVisits is! List) {
expectedVisits = [expectedVisits];
}
Element element;
String cls = test.cls;
String method = test.method;
Expand All @@ -302,6 +315,18 @@ Future test(Set<VisitKind> unvisitedKinds,
"${library.compilationUnit.script.text}");
element = classElement.localLookup(method);
}
var expectedVisits = test.expectedVisits;
if (expectedVisits == null) {
Expect.isTrue(element.isErroneous,
"Element '$method' expected to be have parse errors in:\n"
"${library.compilationUnit.script.text}");
return;
} else if (expectedVisits is! List) {
expectedVisits = [expectedVisits];
}
Expect.isFalse(element.isErroneous,
"Element '$method' is not expected to be have parse errors in:\n"
"${library.compilationUnit.script.text}");

void testAstElement(AstElement astElement) {
Expect.isNotNull(astElement, "Element '$method' not found in:\n"
Expand Down Expand Up @@ -666,5 +691,18 @@ enum VisitKind {
VISIT_UNRESOLVED_PREFIX,
VISIT_UNRESOLVED_POSTFIX,

// TODO(johnniwinther): Add tests for more error cases.
VISIT_IF_NULL,
VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_GET,
VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_SET,
VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_INVOKE,
VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_COMPOUND,
VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_PREFIX,
VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_POSTFIX,

ERROR_INVALID_ASSERT,
ERROR_UNDEFINED_UNARY_EXPRESSION,
ERROR_UNDEFINED_BINARY_EXPRESSION,

VISIT_CONSTANT_GET,
VISIT_CONSTANT_INVOKE,
}
152 changes: 147 additions & 5 deletions tests/compiler/dart2js/semantic_visitor_test_send_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ const Map<String, List<Test>> SEND_TESTS = const {
const Test.clazz(
'''
class C {
static static get o => 42;
static get o => 42;
m() { o = 42; }
}
''',
Expand All @@ -316,7 +316,7 @@ const Map<String, List<Test>> SEND_TESTS = const {
const Test.clazz(
'''
class C {
static static get o => 42;
static get o => 42;
m() { C.o = 42; }
}
''',
Expand All @@ -326,7 +326,7 @@ const Map<String, List<Test>> SEND_TESTS = const {
const Test.prefix(
'''
class C {
static static get o => 42;
static get o => 42;
}
''',
'm() { p.C.o = 42; }',
Expand Down Expand Up @@ -1382,6 +1382,16 @@ const Map<String, List<Test>> SEND_TESTS = const {
m() { assert(false); }
''',
const Visit(VisitKind.VISIT_ASSERT, expression: 'false')),
const Test(
'''
m() { assert(); }
''',
const Visit(VisitKind.ERROR_INVALID_ASSERT, arguments: '()')),
const Test(
'''
m() { assert(42, true); }
''',
const Visit(VisitKind.ERROR_INVALID_ASSERT, arguments: '(42,true)')),
],
'Logical and': const [
// Logical and
Expand Down Expand Up @@ -1541,6 +1551,18 @@ const Map<String, List<Test>> SEND_TESTS = const {
const Visit(VisitKind.VISIT_UNRESOLVED_SUPER_BINARY,
operator: '+',
right: '42')),
const Test(
'''
m() => 2 === 3;
''',
const Visit(VisitKind.ERROR_UNDEFINED_BINARY_EXPRESSION,
left: '2', operator: '===', right: '3')),
const Test(
'''
m() => 2 !== 3;
''',
const Visit(VisitKind.ERROR_UNDEFINED_BINARY_EXPRESSION,
left: '2', operator: '!==', right: '3')),
],
'Index': const [
// Index
Expand Down Expand Up @@ -1782,6 +1804,14 @@ const Map<String, List<Test>> SEND_TESTS = const {
m() => !0;
''',
const Visit(VisitKind.VISIT_NOT, expression: '0')),
const Test(
'''
m() => +false;
''',
// TODO(johnniwinther): Should this be an
// ERROR_UNDEFINED_UNARY_EXPRESSION? Currently the parser just skips
// the `+`.
const []),
],
'Index set': const [
// Index set
Expand Down Expand Up @@ -1851,7 +1881,7 @@ const Map<String, List<Test>> SEND_TESTS = const {
const Test(
'''
m() {
final a;
final a = 0;
a += 42;
}
''',
Expand Down Expand Up @@ -2125,7 +2155,7 @@ const Map<String, List<Test>> SEND_TESTS = const {
var a;
}
class B extends A {
final a;
final a = 0;
}
class C extends B {
Expand Down Expand Up @@ -3367,4 +3397,116 @@ const Map<String, List<Test>> SEND_TESTS = const {
type: 'Class',
selector: 'CallStructure(arity=2)')),
],
'If not null expressions': const [
const Test(
'''
m(a) => a?.b;
''',
const [
const Visit(
VisitKind.VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_GET,
receiver: 'a',
name: 'b'),
const Visit(
VisitKind.VISIT_PARAMETER_GET,
element: 'parameter(m#a)'),
]),
const Test(
'''
m(a) => a?.b = 42;
''',
const [
const Visit(
VisitKind.VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_SET,
receiver: 'a',
name: 'b',
rhs: '42'),
const Visit(
VisitKind.VISIT_PARAMETER_GET,
element: 'parameter(m#a)'),
]),
const Test(
'''
m(a) => a?.b(42, true);
''',
const [
const Visit(
VisitKind.VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_INVOKE,
receiver: 'a',
arguments: '(42,true)',
selector: 'Selector(call, b, arity=2)'),
const Visit(
VisitKind.VISIT_PARAMETER_GET,
element: 'parameter(m#a)'),
]),
const Test(
'''
m(a) => ++a?.b;
''',
const [
const Visit(
VisitKind.VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_PREFIX,
receiver: 'a',
getter: 'Selector(getter, b, arity=0)',
setter: 'Selector(setter, b, arity=1)',
operator: '++'),
const Visit(
VisitKind.VISIT_PARAMETER_GET,
element: 'parameter(m#a)'),
]),
const Test(
'''
m(a) => a?.b--;
''',
const [
const Visit(
VisitKind.VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_POSTFIX,
receiver: 'a',
getter: 'Selector(getter, b, arity=0)',
setter: 'Selector(setter, b, arity=1)',
operator: '--'),
const Visit(
VisitKind.VISIT_PARAMETER_GET,
element: 'parameter(m#a)'),
]),
const Test(
'''
m(a) => a?.b *= 42;
''',
const [
const Visit(
VisitKind.VISIT_IF_NOT_NULL_DYNAMIC_PROPERTY_COMPOUND,
receiver: 'a',
getter: 'Selector(getter, b, arity=0)',
setter: 'Selector(setter, b, arity=1)',
operator: '*=',
rhs: '42'),
const Visit(
VisitKind.VISIT_PARAMETER_GET,
element: 'parameter(m#a)'),
]),
const Test(
'''
m(a, b) => a ?? b;
''',
const [
const Visit(VisitKind.VISIT_IF_NULL,
left: 'a', right: 'b'),
const Visit(
VisitKind.VISIT_PARAMETER_GET,
element: 'parameter(m#a)'),
const Visit(
VisitKind.VISIT_PARAMETER_GET,
element: 'parameter(m#b)'),
]),
const Test(
'''
m(a) => a ??= 42;
''',
const Visit(
VisitKind.VISIT_PARAMETER_COMPOUND,
element: 'parameter(m#a)',
operator: '??=',
rhs: '42')),
],
};
Loading

0 comments on commit deb1697

Please sign in to comment.