Skip to content

Commit 2e34231

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm] Do not mirror default values of parameters of abstract methods
In bytecode mode default values are part of the method body, which is omitted for abstract methods. In anticipation for this future change, default values of parameters of abstract methods are no longer available through dart:mirrors. Please also see #38464 Change-Id: I47742b588690ea96cb3ca636ff86e4e042bfe5a2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117299 Commit-Queue: Alexander Markov <[email protected]> Reviewed-by: Ryan Macnak <[email protected]> Reviewed-by: Siva Annamalai <[email protected]>
1 parent 771ee9f commit 2e34231

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ main() { foo(() {}); }
2020

2121
### Core libraries
2222

23+
* Default values of parameters of abstract methods are no longer available
24+
via `dart:mirrors`.
25+
2326
### Dart VM
2427

2528
### Tools

runtime/vm/kernel.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ class ParameterDescriptorBuilder : public KernelReaderHelper {
571571
type_translator_(this, active_class, /* finalize= */ true),
572572
constant_evaluator_(this, &type_translator_, active_class, nullptr) {}
573573

574-
RawObject* BuildParameterDescriptor(intptr_t kernel_offset);
574+
RawObject* BuildParameterDescriptor(const Function& function);
575575

576576
private:
577577
TypeTranslator type_translator_;
@@ -581,8 +581,8 @@ class ParameterDescriptorBuilder : public KernelReaderHelper {
581581
};
582582

583583
RawObject* ParameterDescriptorBuilder::BuildParameterDescriptor(
584-
intptr_t kernel_offset) {
585-
SetOffset(kernel_offset);
584+
const Function& function) {
585+
SetOffset(function.kernel_offset());
586586
ReadUntilFunctionNode();
587587
FunctionNodeHelper function_node_helper(this);
588588
function_node_helper.ReadUntilExcluding(
@@ -610,17 +610,19 @@ RawObject* ParameterDescriptorBuilder::BuildParameterDescriptor(
610610
helper.IsFinal() ? Bool::True() : Bool::False());
611611

612612
Tag tag = ReadTag(); // read (first part of) initializer.
613-
if (tag == kSomething) {
613+
if ((tag == kSomething) && !function.is_abstract()) {
614614
// this will (potentially) read the initializer, but reset the position.
615615
Instance& constant = Instance::ZoneHandle(
616616
zone_, constant_evaluator_.EvaluateExpression(ReaderOffset()));
617-
SkipExpression(); // read (actual) initializer.
618617
param_descriptor.SetAt(entry_start + Parser::kParameterDefaultValueOffset,
619618
constant);
620619
} else {
621620
param_descriptor.SetAt(entry_start + Parser::kParameterDefaultValueOffset,
622621
Object::null_instance());
623622
}
623+
if (tag == kSomething) {
624+
SkipExpression(); // read (actual) initializer.
625+
}
624626

625627
if (FLAG_enable_mirrors && (helper.annotation_count_ > 0)) {
626628
AlternativeReadingScope alt(&reader_, param_kernel_offset);
@@ -665,7 +667,7 @@ RawObject* BuildParameterDescriptor(const Function& function) {
665667
ExternalTypedData::Handle(zone, function.KernelData()),
666668
function.KernelDataProgramOffset(), &active_class);
667669

668-
return builder.BuildParameterDescriptor(function.kernel_offset());
670+
return builder.BuildParameterDescriptor(function);
669671
} else {
670672
return Thread::Current()->StealStickyError();
671673
}

tests/lib_2/mirrors/parameter_abstract_test.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
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-
// BOGUS: Note that both AST and bytecode modes are missing default values.
6-
75
import 'dart:mirrors';
86

97
import 'package:expect/expect.dart';
@@ -23,12 +21,12 @@ main() {
2321
MethodMirror foo1 = cm.declarations[#foo1];
2422
expect('Method(s(foo1) in s(C), abstract)', foo1);
2523
expect(
26-
'Parameter(s(x) in s(foo1), optional, named, value = Instance(value = 1), type = Class(s(int) in s(dart.core), top-level))',
24+
'Parameter(s(x) in s(foo1), optional, named, type = Class(s(int) in s(dart.core), top-level))',
2725
foo1.parameters[0]);
2826
expect(
29-
'Parameter(s(y) in s(foo1), optional, named, value = Instance(value = 2), type = Class(s(int) in s(dart.core), top-level))',
27+
'Parameter(s(y) in s(foo1), optional, named, type = Class(s(int) in s(dart.core), top-level))',
3028
foo1.parameters[1]);
3129
expect(
32-
'Parameter(s(z) in s(foo1), optional, named, value = Instance(value = 3), type = Class(s(int) in s(dart.core), top-level))',
30+
'Parameter(s(z) in s(foo1), optional, named, type = Class(s(int) in s(dart.core), top-level))',
3331
foo1.parameters[2]);
3432
}

tests/lib_2/mirrors/stringify.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ String stringify(value) {
175175
throw 'Unexpected value: $value';
176176
}
177177

178-
expect(expected, actual, [String reason]) {
178+
expect(expected, actual, [String reason = ""]) {
179179
Expect.stringEquals(expected, stringify(actual), reason);
180180
}
181181

0 commit comments

Comments
 (0)