Skip to content

Commit

Permalink
[vm,mirrors] reflectClass: throw ArgumentError for function and recor…
Browse files Browse the repository at this point in the history
…d 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]>
  • Loading branch information
alexmarkov authored and Commit Queue committed Jan 8, 2025
1 parent 742850f commit 3a73f32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
10 changes: 4 additions & 6 deletions runtime/lib/mirrors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -756,15 +756,13 @@ DEFINE_NATIVE_ENTRY(IsolateMirror_loadUri, 0, 1) {
DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 0, 1) {
GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
ASSERT(type.IsFinalized());
const Class& cls = Class::Handle(
type.IsFunctionType()
? IsolateGroup::Current()->object_store()->closure_class()
: type.type_class());
ASSERT(!cls.IsNull());
if (cls.IsDynamicClass() || cls.IsVoidClass() || cls.IsNeverClass()) {
if (!type.IsType() || type.IsDynamicType() || type.IsVoidType() ||
type.IsNeverType()) {
Exceptions::ThrowArgumentError(type);
UNREACHABLE();
}
const Class& cls = Class::Handle(type.type_class());
ASSERT(!cls.IsNull());
return CreateClassMirror(cls, AbstractType::Handle(cls.DeclarationType()),
Bool::True(), // is_declaration
Object::null_instance());
Expand Down
10 changes: 5 additions & 5 deletions tests/lib/mirrors/reflect_class_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
// 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.

// Formatting can break multitests, so don't format them.
// dart format off

import "dart:mirrors";

import "package:expect/expect.dart";

typedef void FooFunction(int a, double b);
typedef Rec = (int,);
typedef Void = void;

main() {
Expect.throwsArgumentError(() => reflectClass(dynamic));
Expect.throwsArgumentError(() => reflectClass(1)); //# 01: compile-time error
Expect.throwsArgumentError(() => reflectClass("string")); //# 02: compile-time error
Expect.throwsArgumentError(() => reflectClass(Void));
Expect.throwsArgumentError(() => reflectClass(Never));
Expect.throwsArgumentError(() => reflectClass(FooFunction));
Expect.throwsArgumentError(() => reflectClass(Rec));
}

0 comments on commit 3a73f32

Please sign in to comment.