Add consistent_type_error_test

Change-Id: Ic48765468dcdd19371291a32514b9b04012a762a
Reviewed-on: https://dart-review.googlesource.com/c/79146
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Stephen Adams
2018-10-12 00:52:25 +00:00
committed by commit-bot@chromium.org
parent d95f63d752
commit bd223d0ec4
5 changed files with 228 additions and 24 deletions
@@ -176,20 +176,22 @@ class InstantiationStubGenerator {
// For every call-selector generate a stub to the corresponding selector
// with filled-in type arguments.
Set<ParameterStructure> parameterStructures;
for (Selector selector in callSelectors.keys) {
CallStructure callStructure = selector.callStructure;
if (callStructure.typeArgumentCount != 0) continue;
CallStructure genericCallStructure =
callStructure.withTypeArgumentCount(typeArgumentCount);
parameterStructures ??= computeLiveParameterStructures();
for (ParameterStructure parameterStructure in parameterStructures) {
if (genericCallStructure.signatureApplies(parameterStructure)) {
Selector genericSelector =
new Selector.call(selector.memberName, genericCallStructure);
stubs.add(_generateStub(
instantiationClass, functionField, selector, genericSelector));
break;
if (callSelectors != null) {
Set<ParameterStructure> parameterStructures;
for (Selector selector in callSelectors.keys) {
CallStructure callStructure = selector.callStructure;
if (callStructure.typeArgumentCount != 0) continue;
CallStructure genericCallStructure =
callStructure.withTypeArgumentCount(typeArgumentCount);
parameterStructures ??= computeLiveParameterStructures();
for (ParameterStructure parameterStructure in parameterStructures) {
if (genericCallStructure.signatureApplies(parameterStructure)) {
Selector genericSelector =
new Selector.call(selector.memberName, genericCallStructure);
stubs.add(_generateStub(
instantiationClass, functionField, selector, genericSelector));
break;
}
}
}
}
@@ -3407,13 +3407,13 @@ intTypeCast(value) {
void propertyTypeError(value, property) {
String name = isCheckPropertyToJsConstructorName(property);
throw new TypeErrorImplementation(value, name);
throw new TypeErrorImplementation(value, unminifyOrTag(name));
}
void propertyTypeCastError(value, property) {
// Cuts the property name to the class name.
String expectedType = property.substring(3, property.length);
throw new CastErrorImplementation(value, expectedType);
String name = isCheckPropertyToJsConstructorName(property);
throw new CastErrorImplementation(value, unminifyOrTag(name));
}
/**
@@ -3537,12 +3537,12 @@ stringSuperNativeTypeCast(value, property) {
listTypeCheck(value) {
if (value == null) return value;
if (value is List) return value;
throw new TypeErrorImplementation(value, 'List');
throw new TypeErrorImplementation(value, 'List<dynamic>');
}
listTypeCast(value) {
if (value is List || value == null) return value;
throw new CastErrorImplementation(value, 'List');
throw new CastErrorImplementation(value, 'List<dynamic>');
}
listSuperTypeCheck(value, property) {
+1 -1
View File
@@ -463,7 +463,7 @@ String computeTypeName(String isField, List arguments) {
// Extract the class name from the is field and append the textual
// representation of the type arguments.
return Primitives.formatType(
isCheckPropertyToJsConstructorName(isField), arguments);
unminifyOrTag(isCheckPropertyToJsConstructorName(isField)), arguments);
}
/// Called from generated code.
@@ -19,9 +19,8 @@
"Dynamic access of '_js_helper::_self'.": 1,
"Dynamic access of '_js_helper::_target'.": 1,
"Dynamic access of '_js_helper::_receiver'.": 1,
"Dynamic access of 'length'.": 3,
"Dynamic invocation of '>='.": 1,
"Dynamic invocation of 'substring'.": 1
"Dynamic access of 'length'.": 2,
"Dynamic invocation of '>='.": 1
},
"org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/string_helper.dart": {
"Dynamic invocation of '<'.": 1,
@@ -322,4 +321,4 @@
"Dynamic access of 'port'.": 1,
"Dynamic invocation of 'dart._http::_toJSON'.": 1
}
}
}
@@ -0,0 +1,203 @@
// Copyright (c) 2018, 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.
// Test that type checks give consistent errors for the same types. In minified
// mode this checks that the minified class names are consistently tagged.
import 'package:expect/expect.dart';
class Plain {}
class Foo<U> {}
class Test<T> {
@pragma('dart2js:noInline')
asT(o) => o as T;
@pragma('dart2js:noInline')
asFooT(o) => o as Foo<T>;
@pragma('dart2js:noInline')
testT(o) {
T result = o;
}
@pragma('dart2js:noInline')
testFooT(o) {
Foo<T> result = o;
}
}
capture(action()) {
try {
action();
} catch (e) {
print('$e');
return '$e';
}
Expect.fail('Action should have failed');
}
dynamic g;
casts() {
g = Foo<String>();
Expect.equals(
capture(() => Test<Foo<Plain>>().asT(g)),
capture(() => g as Foo<Plain>),
"C1",
);
Expect.equals(
capture(() => g as Foo<Plain>),
capture(() => Test<Plain>().asFooT(g)),
"C2",
);
Expect.equals(
capture(() => Test<Plain>().asT(g)),
capture(() => g as Plain),
"C3",
);
g = Foo<Plain>();
Expect.equals(
capture(() => Test<Foo<String>>().asT(g)),
capture(() => g as Foo<String>),
"C4",
);
Expect.equals(
capture(() => g as Foo<String>),
capture(() => Test<String>().asFooT(g)),
"C5",
);
g = Plain();
Expect.equals(
capture(() => Test<String>().asT(g)),
capture(() => g as String),
"C6",
);
Expect.equals(
capture(() => Test<int>().asT(g)),
capture(() => g as int),
"C7",
);
Expect.equals(
capture(() => Test<double>().asT(g)),
capture(() => g as double),
"C8",
);
Expect.equals(
capture(() => Test<bool>().asT(g)),
capture(() => g as bool),
"C9",
);
Expect.equals(
capture(() => Test<List>().asT(g)),
capture(() => g as List),
"C10",
);
}
tests() {
g = Foo<String>();
Expect.equals(
capture(() => Test<Foo<Plain>>().testT(g)),
capture(() {
Foo<Plain> x = g;
}),
"T1",
);
Expect.equals(
capture(() {
Foo<Plain> x = g;
}),
capture(() => Test<Plain>().testFooT(g)),
"T2",
);
Expect.equals(
capture(() => Test<Plain>().testT(g)),
capture(() {
Plain x = g;
}),
"T3",
);
g = Foo<Plain>();
Expect.equals(
capture(() => Test<Foo<String>>().testT(g)),
capture(() {
Foo<String> x = g;
}),
"T4",
);
Expect.equals(
capture(() {
Foo<String> x = g;
}),
capture(() => Test<String>().testFooT(g)),
"T5",
);
g = Plain();
Expect.equals(
capture(() => Test<String>().testT(g)),
capture(() {
String x = g;
}),
"T6",
);
Expect.equals(
capture(() => Test<int>().testT(g)),
capture(() {
int x = g;
}),
"T7",
);
Expect.equals(
capture(() => Test<double>().testT(g)),
capture(() {
double x = g;
}),
"T8",
);
Expect.equals(
capture(() => Test<bool>().testT(g)),
capture(() {
bool x = g;
}),
"T9",
);
Expect.equals(
capture(() => Test<List>().testT(g)),
capture(() {
List x = g;
}),
"T10",
);
}
main() {
casts();
tests();
}