blob: 48ebf3e467bec3e57be18f8228d18e2657cbc406 [file] [log] [blame]
// Copyright (c) 2020, 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:test_reflective_loader/test_reflective_loader.dart';
import '../../constant/potentially_constant_test.dart';
import '../driver_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(LocalVariableTest);
defineReflectiveTests(LocalVariableWithNullSafetyTest);
});
}
@reflectiveTest
class LocalVariableTest extends DriverResolutionTest {
test_int() async {
await resolveTestCode('''
void f() {
var v = 0;
v;
}
''');
_assertTypeOfV('int');
}
test_null() async {
await resolveTestCode('''
void f() {
var v = null;
v;
}
''');
_assertTypeOfV('dynamic');
}
void _assertTypeOfV(String expected) {
assertType(findElement.localVar('v').type, expected);
assertType(findNode.simple('v;'), expected);
}
}
@reflectiveTest
class LocalVariableWithNullSafetyTest extends LocalVariableTest
with WithNullSafetyMixin {
test_Never() async {
await resolveTestCode('''
void f(Never a) {
var v = a;
v;
}
''');
_assertTypeOfV('Never');
}
}