Temporary revert to fix issue #35009 for 2.1. package:rpc relies on mirrors behaviour that is not valid for Dart 2, so these type checks cause the package to crash.
Revert "[ VM / Mirrors ] Added type checking to enforce strong mode semantics when using dart:mirrors"
This reverts commit 9f00eec55bc56dc7371ffcc509d4b7d6698fc51c.
Change-Id: I82ce07d388ba9402f20caf700815b39c9bc418f6
Reviewed-on: https://dart-review.googlesource.com/c/83225
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc
index 7620f94..5b64e98 100644
--- a/runtime/lib/mirrors.cc
+++ b/runtime/lib/mirrors.cc
@@ -1444,13 +1444,6 @@
InvocationMirror::kMethod);
UNREACHABLE();
}
- const Object& type_error =
- Object::Handle(redirected_constructor.DoArgumentTypesMatch(
- args, args_descriptor, type_arguments));
- if (!type_error.IsNull()) {
- Exceptions::PropagateError(Error::Cast(type_error));
- UNREACHABLE();
- }
Instance& new_object = Instance::Handle();
if (redirected_constructor.IsGenerativeConstructor()) {
diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc
index 5575c64..995a437 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -4158,16 +4158,6 @@
EXPECT_STREQ("myerror", Dart_GetError(result));
}
-TEST_CASE(DartAPI_SetField_BadType) {
- const char* kScriptChars = "int foo;\n";
- Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
- Dart_Handle name = NewString("foo");
- Dart_Handle result = Dart_SetField(lib, name, Dart_True());
- EXPECT(Dart_IsError(result));
- EXPECT_SUBSTRING("type 'bool' is not a subtype of type 'int' of 'foo'",
- Dart_GetError(result));
-}
-
void NativeFieldLookup(Dart_NativeArguments args) {
UNREACHABLE();
}
@@ -5151,88 +5141,6 @@
EXPECT_STREQ("myerror", Dart_GetError(result));
}
-TEST_CASE(DartAPI_Invoke_BadArgs) {
- const char* kScriptChars =
- "class BaseMethods {\n"
- " inheritedMethod(int arg) => 'inherited $arg';\n"
- " static nonInheritedMethod(int arg) => 'noninherited $arg';\n"
- "}\n"
- "\n"
- "class Methods extends BaseMethods {\n"
- " instanceMethod(int arg) => 'instance $arg';\n"
- " _instanceMethod(int arg) => 'hidden instance $arg';\n"
- " static staticMethod(int arg) => 'static $arg';\n"
- " static _staticMethod(int arg) => 'hidden static $arg';\n"
- "}\n"
- "\n"
- "topMethod(int arg) => 'top $arg';\n"
- "_topMethod(int arg) => 'hidden top $arg';\n"
- "\n"
- "Methods test() {\n"
- " return new Methods();\n"
- "}\n";
-
-#if defined(PRODUCT)
- const char* error_msg =
- "type '_OneByteString' is not a subtype of type 'int' of 'arg'";
-#else
- const char* error_msg =
- "type 'String' is not a subtype of type 'int' of 'arg'";
-#endif // defined(PRODUCT)
-
- // Shared setup.
- Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
- Dart_Handle type = Dart_GetType(lib, NewString("Methods"), 0, NULL);
- EXPECT_VALID(type);
- Dart_Handle instance = Dart_Invoke(lib, NewString("test"), 0, NULL);
- EXPECT_VALID(instance);
- Dart_Handle args[1];
- args[0] = NewString("!!!");
- Dart_Handle result;
- Dart_Handle name;
-
- // Instance method.
- name = NewString("instanceMethod");
- result = Dart_Invoke(instance, name, 1, args);
- EXPECT(Dart_IsError(result));
- EXPECT_SUBSTRING(error_msg, Dart_GetError(result));
-
- name = PrivateLibName(lib, "_instanceMethod");
- result = Dart_Invoke(instance, name, 1, args);
- EXPECT(Dart_IsError(result));
- EXPECT_SUBSTRING(error_msg, Dart_GetError(result));
-
- // Inherited method.
- name = NewString("inheritedMethod");
- result = Dart_Invoke(instance, name, 1, args);
- EXPECT(Dart_IsError(result));
- EXPECT_SUBSTRING(error_msg, Dart_GetError(result));
-
- // Static method.
- name = NewString("staticMethod");
- result = Dart_Invoke(type, name, 1, args);
- EXPECT(Dart_IsError(result));
- EXPECT_SUBSTRING(error_msg, Dart_GetError(result));
-
- // Hidden static method.
- name = NewString("_staticMethod");
- result = Dart_Invoke(type, name, 1, args);
- EXPECT(Dart_IsError(result));
- EXPECT_SUBSTRING(error_msg, Dart_GetError(result));
-
- // Top-Level method.
- name = NewString("topMethod");
- result = Dart_Invoke(lib, name, 1, args);
- EXPECT(Dart_IsError(result));
- EXPECT_SUBSTRING(error_msg, Dart_GetError(result));
-
- // Hidden top-level method.
- name = NewString("_topMethod");
- result = Dart_Invoke(lib, name, 1, args);
- EXPECT(Dart_IsError(result));
- EXPECT_SUBSTRING(error_msg, Dart_GetError(result));
-}
-
TEST_CASE(DartAPI_Invoke_Null) {
Dart_Handle result = Dart_Invoke(Dart_Null(), NewString("toString"), 0, NULL);
EXPECT_VALID(result);
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 4bec000..2e524cc 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -3385,26 +3385,6 @@
return DartEntry::InvokeFunction(throwNew, args);
}
-static RawObject* ThrowTypeError(const TokenPosition token_pos,
- const Instance& src_value,
- const AbstractType& dst_type,
- const String& dst_name) {
- const Array& args = Array::Handle(Array::New(5));
- const Smi& pos = Smi::Handle(Smi::New(token_pos.value()));
- args.SetAt(0, pos);
- args.SetAt(1, src_value);
- args.SetAt(2, dst_type);
- args.SetAt(3, dst_name);
- args.SetAt(4, String::Handle()); // bound error message
-
- const Library& libcore = Library::Handle(Library::CoreLibrary());
- const Class& TypeError =
- Class::Handle(libcore.LookupClassAllowPrivate(Symbols::TypeError()));
- const Function& throwNew = Function::Handle(
- TypeError.LookupFunctionAllowPrivate(Symbols::ThrowNew()));
- return DartEntry::InvokeFunction(throwNew, args);
-}
-
RawObject* Class::InvokeGetter(const String& getter_name,
bool throw_nsm_if_absent,
bool respect_reflectable) const {
@@ -3469,31 +3449,21 @@
const String& internal_setter_name =
String::Handle(zone, Field::SetterName(setter_name));
- AbstractType& parameter_type = AbstractType::Handle(zone);
- AbstractType& argument_type =
- AbstractType::Handle(zone, value.GetType(Heap::kOld));
-
if (field.IsNull()) {
const Function& setter =
Function::Handle(zone, LookupStaticFunction(internal_setter_name));
+
const int kNumArgs = 1;
const Array& args = Array::Handle(zone, Array::New(kNumArgs));
args.SetAt(0, value);
+
if (setter.IsNull() || (respect_reflectable && !setter.is_reflectable())) {
return ThrowNoSuchMethod(AbstractType::Handle(zone, RareType()),
internal_setter_name, args, Object::null_array(),
InvocationMirror::kStatic,
InvocationMirror::kSetter);
}
- parameter_type ^= setter.ParameterTypeAt(0);
- if (!argument_type.IsNullType() && !parameter_type.IsDynamicType() &&
- !value.IsInstanceOf(parameter_type, Object::null_type_arguments(),
- Object::null_type_arguments(), NULL)) {
- const String& argument_name =
- String::Handle(zone, setter.ParameterNameAt(0));
- return ThrowTypeError(setter.token_pos(), value, parameter_type,
- argument_name);
- }
+
// Invoke the setter and return the result.
return DartEntry::InvokeFunction(setter, args);
}
@@ -3502,20 +3472,13 @@
const int kNumArgs = 1;
const Array& args = Array::Handle(zone, Array::New(kNumArgs));
args.SetAt(0, value);
+
return ThrowNoSuchMethod(AbstractType::Handle(zone, RareType()),
internal_setter_name, args, Object::null_array(),
InvocationMirror::kStatic,
InvocationMirror::kSetter);
}
- parameter_type ^= field.type();
- if (!argument_type.IsNullType() && !parameter_type.IsDynamicType() &&
- !value.IsInstanceOf(parameter_type, Object::null_type_arguments(),
- Object::null_type_arguments(), NULL)) {
- const String& argument_name = String::Handle(zone, field.name());
- return ThrowTypeError(field.token_pos(), value, parameter_type,
- argument_name);
- }
field.SetStaticValue(value);
return value.raw();
}
@@ -3565,21 +3528,19 @@
return DartEntry::InvokeClosure(call_args, call_args_descriptor_array);
}
}
+
const Array& args_descriptor_array = Array::Handle(
zone, ArgumentsDescriptor::New(kTypeArgsLen, args.Length(), arg_names));
+
ArgumentsDescriptor args_descriptor(args_descriptor_array);
- const TypeArguments& type_args = Object::null_type_arguments();
+
if (function.IsNull() || !function.AreValidArguments(args_descriptor, NULL) ||
(respect_reflectable && !function.is_reflectable())) {
return ThrowNoSuchMethod(
AbstractType::Handle(zone, RareType()), function_name, args, arg_names,
InvocationMirror::kStatic, InvocationMirror::kMethod);
}
- RawObject* type_error =
- function.DoArgumentTypesMatch(args, args_descriptor, type_args);
- if (type_error != Error::null()) {
- return type_error;
- }
+
return DartEntry::InvokeFunction(function, args, args_descriptor_array);
}
@@ -7004,87 +6965,6 @@
return true;
}
-RawObject* Function::DoArgumentTypesMatch(
- const Array& args,
- const ArgumentsDescriptor& args_desc,
- const TypeArguments& instantiator_type_args) const {
- Thread* thread = Thread::Current();
- Zone* zone = thread->zone();
- Function& instantiated_func = Function::Handle(zone, raw());
-
- if (!HasInstantiatedSignature()) {
- instantiated_func ^= InstantiateSignatureFrom(instantiator_type_args,
- Object::null_type_arguments(),
- kAllFree, Heap::kOld);
- }
- AbstractType& argument_type = AbstractType::Handle(zone);
- AbstractType& parameter_type = AbstractType::Handle(zone);
- Instance& argument = Instance::Handle(zone);
-
- // Check types of the provided arguments against the expected parameter types.
- for (intptr_t i = args_desc.FirstArgIndex(); i < args_desc.PositionalCount();
- ++i) {
- argument ^= args.At(i);
- argument_type ^= argument.GetType(Heap::kOld);
- parameter_type ^= instantiated_func.ParameterTypeAt(i);
-
- // If the argument type is dynamic or the parameter is null, move on.
- if (parameter_type.IsDynamicType() || argument_type.IsNullType()) {
- continue;
- }
- if (!argument.IsInstanceOf(parameter_type, instantiator_type_args,
- Object::null_type_arguments(), NULL)) {
- String& argument_name = String::Handle(zone, ParameterNameAt(i));
- return ThrowTypeError(token_pos(), argument, parameter_type,
- argument_name);
- }
- }
-
- const intptr_t num_arguments = args_desc.Count();
- const intptr_t num_named_arguments = args_desc.NamedCount();
- if (num_named_arguments == 0) {
- return Error::null();
- }
-
- String& argument_name = String::Handle(zone);
- String& parameter_name = String::Handle(zone);
-
- // Check types of named arguments against expected parameter type.
- for (intptr_t i = 0; i < num_named_arguments; i++) {
- argument_name ^= args_desc.NameAt(i);
- ASSERT(argument_name.IsSymbol());
- bool found = false;
- const intptr_t num_positional_args = num_arguments - num_named_arguments;
- const int num_parameters = NumParameters();
-
- // Try to find the named parameter that matches the provided argument.
- for (intptr_t j = num_positional_args; !found && (j < num_parameters);
- j++) {
- parameter_name = ParameterNameAt(j);
- ASSERT(argument_name.IsSymbol());
- if (argument_name.Equals(parameter_name)) {
- found = true;
- argument ^= args.At(args_desc.PositionAt(i));
- argument_type ^= argument.GetType(Heap::kOld);
- parameter_type ^= instantiated_func.ParameterTypeAt(j);
-
- // If the argument type is dynamic or the parameter is null, move on.
- if (parameter_type.IsDynamicType() || argument_type.IsNullType()) {
- continue;
- }
- if (!argument.IsInstanceOf(parameter_type, instantiator_type_args,
- Object::null_type_arguments(), NULL)) {
- String& argument_name = String::Handle(zone, ParameterNameAt(i));
- return ThrowTypeError(token_pos(), argument, parameter_type,
- argument_name);
- }
- }
- }
- ASSERT(found);
- }
- return Error::null();
-}
-
// Helper allocating a C string buffer in the zone, printing the fully qualified
// name of a function in it, and replacing ':' by '_' to make sure the
// constructed name is a valid C++ identifier for debugging purpose.
@@ -11272,14 +11152,12 @@
}
// Invoke the function, or noSuchMethod if it is null.
-static RawObject* InvokeInstanceFunction(
- const Instance& receiver,
- const Function& function,
- const String& target_name,
- const Array& args,
- const Array& args_descriptor_array,
- bool respect_reflectable,
- const TypeArguments& instantiator_type_args) {
+static RawObject* InvokeInstanceFunction(const Instance& receiver,
+ const Function& function,
+ const String& target_name,
+ const Array& args,
+ const Array& args_descriptor_array,
+ bool respect_reflectable) {
// Note "args" is already the internal arguments with the receiver as the
// first element.
ArgumentsDescriptor args_descriptor(args_descriptor_array);
@@ -11288,11 +11166,6 @@
return DartEntry::InvokeNoSuchMethod(receiver, target_name, args,
args_descriptor_array);
}
- RawObject* type_error = function.DoArgumentTypesMatch(args, args_descriptor,
- instantiator_type_args);
- if (type_error != Error::null()) {
- return type_error;
- }
return DartEntry::InvokeFunction(function, args, args_descriptor_array);
}
@@ -11354,16 +11227,9 @@
Object& obj = Object::Handle(LookupLocalOrReExportObject(setter_name));
const String& internal_setter_name =
String::Handle(Field::SetterName(setter_name));
- AbstractType& setter_type = AbstractType::Handle();
- AbstractType& argument_type = AbstractType::Handle(value.GetType(Heap::kOld));
+
if (obj.IsField()) {
const Field& field = Field::Cast(obj);
- setter_type ^= field.type();
- if (!argument_type.IsNullType() && !setter_type.IsDynamicType() &&
- !value.IsInstanceOf(setter_type, Object::null_type_arguments(),
- Object::null_type_arguments(), NULL)) {
- return ThrowTypeError(field.token_pos(), value, setter_type, setter_name);
- }
if (field.is_final() || (respect_reflectable && !field.is_reflectable())) {
const int kNumArgs = 1;
const Array& args = Array::Handle(Array::New(kNumArgs));
@@ -11394,13 +11260,6 @@
InvocationMirror::kTopLevel, InvocationMirror::kSetter);
}
- setter_type ^= setter.ParameterTypeAt(0);
- if (!argument_type.IsNullType() && !setter_type.IsDynamicType() &&
- !value.IsInstanceOf(setter_type, Object::null_type_arguments(),
- Object::null_type_arguments(), NULL)) {
- return ThrowTypeError(setter.token_pos(), value, setter_type, setter_name);
- }
-
return DartEntry::InvokeFunction(setter, args);
}
@@ -11442,7 +11301,7 @@
const Array& args_descriptor_array = Array::Handle(
ArgumentsDescriptor::New(kTypeArgsLen, args.Length(), arg_names));
ArgumentsDescriptor args_descriptor(args_descriptor_array);
- const TypeArguments& type_args = Object::null_type_arguments();
+
if (function.IsNull() || !function.AreValidArguments(args_descriptor, NULL) ||
(respect_reflectable && !function.is_reflectable())) {
return ThrowNoSuchMethod(
@@ -11450,11 +11309,7 @@
function_name, args, arg_names, InvocationMirror::kTopLevel,
InvocationMirror::kMethod);
}
- RawObject* type_error =
- function.DoArgumentTypesMatch(args, args_descriptor, type_args);
- if (type_error != Error::null()) {
- return type_error;
- }
+
return DartEntry::InvokeFunction(function, args, args_descriptor_array);
}
@@ -16067,10 +15922,6 @@
Zone* zone = Thread::Current()->zone();
Class& klass = Class::Handle(zone, clazz());
- TypeArguments& type_args = TypeArguments::Handle(zone);
- if (klass.NumTypeArguments() > 0) {
- type_args ^= GetTypeArguments();
- }
const String& internal_getter_name =
String::Handle(zone, Field::GetterName(getter_name));
@@ -16095,8 +15946,7 @@
zone, ArgumentsDescriptor::New(kTypeArgsLen, args.Length()));
return InvokeInstanceFunction(*this, function, internal_getter_name, args,
- args_descriptor, respect_reflectable,
- type_args);
+ args_descriptor, respect_reflectable);
}
RawObject* Instance::InvokeSetter(const String& setter_name,
@@ -16105,11 +15955,6 @@
Zone* zone = Thread::Current()->zone();
const Class& klass = Class::Handle(zone, clazz());
- TypeArguments& type_args = TypeArguments::Handle(zone);
- if (klass.NumTypeArguments() > 0) {
- type_args ^= GetTypeArguments();
- }
-
const String& internal_setter_name =
String::Handle(zone, Field::SetterName(setter_name));
const Function& setter = Function::Handle(
@@ -16124,8 +15969,7 @@
zone, ArgumentsDescriptor::New(kTypeArgsLen, args.Length()));
return InvokeInstanceFunction(*this, setter, internal_setter_name, args,
- args_descriptor, respect_reflectable,
- type_args);
+ args_descriptor, respect_reflectable);
}
RawObject* Instance::Invoke(const String& function_name,
@@ -16142,11 +15986,6 @@
const Array& args_descriptor = Array::Handle(
zone, ArgumentsDescriptor::New(kTypeArgsLen, args.Length(), arg_names));
- TypeArguments& type_args = TypeArguments::Handle(zone);
- if (klass.NumTypeArguments() > 0) {
- type_args ^= GetTypeArguments();
- }
-
if (function.IsNull()) {
// Didn't find a method: try to find a getter and invoke call on its result.
const String& getter_name =
@@ -16161,9 +16000,9 @@
const Array& getter_args_descriptor = Array::Handle(
zone, ArgumentsDescriptor::New(kTypeArgsLen, getter_args.Length()));
const Object& getter_result = Object::Handle(
- zone, InvokeInstanceFunction(*this, function, getter_name,
- getter_args, getter_args_descriptor,
- respect_reflectable, type_args));
+ zone,
+ InvokeInstanceFunction(*this, function, getter_name, getter_args,
+ getter_args_descriptor, respect_reflectable));
if (getter_result.IsError()) {
return getter_result.raw();
}
@@ -16176,8 +16015,7 @@
// Found an ordinary method.
return InvokeInstanceFunction(*this, function, function_name, args,
- args_descriptor, respect_reflectable,
- type_args);
+ args_descriptor, respect_reflectable);
}
RawObject* Instance::Evaluate(const Class& method_cls,
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index 635a623..f792344 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -2680,13 +2680,6 @@
intptr_t num_named_arguments,
String* error_message) const;
- // Returns a TypeError if the provided arguments don't match the function
- // parameter types, NULL otherwise. Assumes AreValidArguments is called first.
- RawObject* DoArgumentTypesMatch(
- const Array& args,
- const ArgumentsDescriptor& arg_names,
- const TypeArguments& instantiator_type_args) const;
-
// Returns true if the type argument count, total argument count and the names
// of optional arguments are valid for calling this function.
// Otherwise, it returns false and the reason (if error_message is not NULL).
diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc
index 4bd2ccd..e46a8b3 100644
--- a/runtime/vm/service.cc
+++ b/runtime/vm/service.cc
@@ -2362,6 +2362,7 @@
// We don't use Instance::Cast here because it doesn't allow null.
Instance& instance = Instance::Handle(zone);
instance ^= receiver.raw();
+
const Object& result =
Object::Handle(zone, instance.Invoke(selector, args, arg_names));
result.PrintJSON(js, true);
diff --git a/tests/lib_2/mirrors/bad_argument_types_test.dart b/tests/lib_2/mirrors/bad_argument_types_test.dart
deleted file mode 100644
index 8063803..0000000
--- a/tests/lib_2/mirrors/bad_argument_types_test.dart
+++ /dev/null
@@ -1,157 +0,0 @@
-// 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.
-
-import 'dart:io';
-import 'dart:mirrors';
-
-import 'package:expect/expect.dart';
-
-int foobar = 1;
-
-set foobaz(int x) {
- foobar = x;
-}
-
-void foo(Map<String, String> m) {
- print(m);
- print(m['bar']);
-}
-
-void bar<T extends num>(T a) {
- print(a);
-}
-
-class Foo {
- Map<String, String> bork;
- static Map<String, String> bark;
- static set woof(Map<String, String> x) {
- bark = x;
- }
-
- Foo(Map<String, String> m) {
- print(m);
- }
-
- Foo.a();
-
- static void baz(Map<String, String> m, {String bar}) {
- print('baz');
- print(m['bar']);
- print(bar);
- }
-
- void bar(Map<String, String> m) {
- print('bar');
- print(m.runtimeType);
- }
-}
-
-class FooBar<T extends num> {
- T bar;
- FooBar(this.bar) {
- print(bar);
- }
-
- set barz(T x) {
- bar = x;
- }
-
- factory FooBar.baz(T bar) {
- print(bar);
- return FooBar(bar);
- }
-
- void foobar<S>(T a, S b) {
- print(a);
- print(b);
- }
-}
-
-void badClassStaticInvoke() {
- Map<String, String> map = Map<String, String>();
- map['bar'] = 'Hello world!';
- final cm = reflectClass(Foo);
- Expect.throwsTypeError(() => cm.invoke(#baz, [
- map
- ], {
- #bar: {'boo': 'bah'}
- }));
-}
-
-void badStaticInvoke() {
- final ClosureMirror im = reflect(foo);
- Expect.throwsTypeError(() => im.apply(['Hello world!']));
-}
-
-void badInstanceInvoke() {
- final fooCls = Foo.a();
- final im = reflect(fooCls);
- Expect.throwsTypeError(() => im.invoke(#bar, ['Hello World!']));
-}
-
-void badConstructorInvoke() {
- final cm = reflectClass(Foo);
- Expect.throwsTypeError(() => cm.newInstance(Symbol(''), ['Hello World!']));
-}
-
-void badSetterInvoke() {
- final fooCls = Foo.a();
- final im = reflect(fooCls);
- Expect.throwsTypeError(() => im.setField(#bork, 'Hello World!'));
-}
-
-void badStaticSetterInvoke() {
- final cm = reflectClass(Foo);
- Expect.throwsTypeError(() => cm.setField(#bark, 'Hello World!'));
- Expect.throwsTypeError(() => cm.setField(#woof, 'Hello World!'));
-}
-
-void badGenericConstructorInvoke() {
- final cm = reflectType(FooBar, [int]) as ClassMirror;
- Expect.throwsTypeError(() => cm.newInstance(Symbol(''), ['Hello World!']));
-}
-
-void badGenericClassStaticInvoke() {
- final cm = reflectType(FooBar, [int]) as ClassMirror;
- final im = cm.newInstance(Symbol(''), [1]);
- Expect.throwsTypeError(() => im.invoke(#foobar, ['Hello', 'World']));
-}
-
-void badGenericFactoryInvoke() {
- final cm = reflectType(FooBar, [int]) as ClassMirror;
- Expect.throwsTypeError(() => cm.newInstance(Symbol('baz'), ['Hello World!']));
-}
-
-void badGenericStaticInvoke() {
- final ClosureMirror im = reflect(bar);
- Expect.throwsTypeError(() => im.apply(['Hello world!']));
-}
-
-void badGenericSetterInvoke() {
- final cm = reflectType(FooBar, [int]) as ClassMirror;
- final im = cm.newInstance(Symbol(''), [0]);
- Expect.throwsTypeError(() => im.setField(#bar, 'Hello world!'));
- Expect.throwsTypeError(() => im.setField(#barz, 'Hello world!'));
-}
-
-void badLibrarySetterInvoke() {
- final lm = currentMirrorSystem().findLibrary(Symbol(''));
- Expect.throwsTypeError(() => lm.setField(#foobar, 'Foobaz'));
- Expect.throwsTypeError(() => lm.setField(#foobaz, 'Foobaz'));
-}
-
-void main() {
- badClassStaticInvoke();
- badStaticInvoke();
- badInstanceInvoke();
- badConstructorInvoke();
- badSetterInvoke();
- badStaticSetterInvoke();
- badGenericConstructorInvoke();
- badGenericClassStaticInvoke();
- badGenericFactoryInvoke();
- badGenericStaticInvoke();
- badGenericSetterInvoke();
- badLibrarySetterInvoke();
-}