blob: 3713aef046bd9e1a5510c812984060729170fa06 [file] [log] [blame]
// Copyright (c) 2019, 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.
import 'package:analyzer/src/error/codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../dart/resolution/driver_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(UndefinedGetterTest);
});
}
@reflectiveTest
class UndefinedGetterTest extends DriverResolutionTest {
test_ifElement_inList_notPromoted() async {
await assertErrorCodesInCode('''
f(int x) {
return [if (x is String) x.length];
}
''', [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
test_ifElement_inList_promoted() async {
await assertNoErrorsInCode('''
f(Object x) {
return [if (x is String) x.length];
}
''');
}
test_ifElement_inMap_notPromoted() async {
await assertErrorCodesInCode('''
f(int x) {
return {if (x is String) x : x.length};
}
''', [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
test_ifElement_inMap_promoted() async {
await assertNoErrorsInCode('''
f(Object x) {
return {if (x is String) x : x.length};
}
''');
}
test_ifElement_inSet_notPromoted() async {
await assertErrorCodesInCode('''
f(int x) {
return {if (x is String) x.length};
}
''', [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
test_ifElement_inSet_promoted() async {
await assertNoErrorsInCode('''
f(Object x) {
return {if (x is String) x.length};
}
''');
}
test_ifStatement_notPromoted() async {
await assertErrorCodesInCode('''
f(int x) {
if (x is String) {
x.length;
}
}
''', [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
test_ifStatement_promoted() async {
await assertNoErrorsInCode('''
f(Object x) {
if (x is String) {
x.length;
}
}
''');
}
test_promotedTypeParameter_regress35305() async {
await assertErrorCodesInCode(r'''
void f<X extends num, Y extends X>(Y y) {
if (y is int) {
y.isEven;
}
}
''', [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
}