Skip to content

Commit 3a73f32

Browse files
alexmarkovCommit Queue
authored andcommitted
[vm,mirrors] reflectClass: throw ArgumentError for function and record types
TEST=tests/lib/mirrors/reflect_class_test.dart Fixes #59863 Change-Id: Ic9ab394da9abeb7f793556a4827a496c372576a0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403620 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent 742850f commit 3a73f32

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

runtime/lib/mirrors.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -756,15 +756,13 @@ DEFINE_NATIVE_ENTRY(IsolateMirror_loadUri, 0, 1) {
756756
DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 0, 1) {
757757
GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
758758
ASSERT(type.IsFinalized());
759-
const Class& cls = Class::Handle(
760-
type.IsFunctionType()
761-
? IsolateGroup::Current()->object_store()->closure_class()
762-
: type.type_class());
763-
ASSERT(!cls.IsNull());
764-
if (cls.IsDynamicClass() || cls.IsVoidClass() || cls.IsNeverClass()) {
759+
if (!type.IsType() || type.IsDynamicType() || type.IsVoidType() ||
760+
type.IsNeverType()) {
765761
Exceptions::ThrowArgumentError(type);
766762
UNREACHABLE();
767763
}
764+
const Class& cls = Class::Handle(type.type_class());
765+
ASSERT(!cls.IsNull());
768766
return CreateClassMirror(cls, AbstractType::Handle(cls.DeclarationType()),
769767
Bool::True(), // is_declaration
770768
Object::null_instance());

tests/lib/mirrors/reflect_class_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// Formatting can break multitests, so don't format them.
6-
// dart format off
7-
85
import "dart:mirrors";
96

107
import "package:expect/expect.dart";
118

129
typedef void FooFunction(int a, double b);
10+
typedef Rec = (int,);
11+
typedef Void = void;
1312

1413
main() {
1514
Expect.throwsArgumentError(() => reflectClass(dynamic));
16-
Expect.throwsArgumentError(() => reflectClass(1)); //# 01: compile-time error
17-
Expect.throwsArgumentError(() => reflectClass("string")); //# 02: compile-time error
15+
Expect.throwsArgumentError(() => reflectClass(Void));
16+
Expect.throwsArgumentError(() => reflectClass(Never));
1817
Expect.throwsArgumentError(() => reflectClass(FooFunction));
18+
Expect.throwsArgumentError(() => reflectClass(Rec));
1919
}

0 commit comments

Comments
 (0)