diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bccb77cd47..e6efa0d11d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,9 @@ main() { foo(() {}); } ### Core libraries +* Default values of parameters of abstract methods are no longer available + via `dart:mirrors`. + ### Dart VM ### Tools diff --git a/runtime/vm/kernel.cc b/runtime/vm/kernel.cc index 0760b1f182e..73a3dfb21ae 100644 --- a/runtime/vm/kernel.cc +++ b/runtime/vm/kernel.cc @@ -571,7 +571,7 @@ class ParameterDescriptorBuilder : public KernelReaderHelper { type_translator_(this, active_class, /* finalize= */ true), constant_evaluator_(this, &type_translator_, active_class, nullptr) {} - RawObject* BuildParameterDescriptor(intptr_t kernel_offset); + RawObject* BuildParameterDescriptor(const Function& function); private: TypeTranslator type_translator_; @@ -581,8 +581,8 @@ class ParameterDescriptorBuilder : public KernelReaderHelper { }; RawObject* ParameterDescriptorBuilder::BuildParameterDescriptor( - intptr_t kernel_offset) { - SetOffset(kernel_offset); + const Function& function) { + SetOffset(function.kernel_offset()); ReadUntilFunctionNode(); FunctionNodeHelper function_node_helper(this); function_node_helper.ReadUntilExcluding( @@ -610,17 +610,19 @@ RawObject* ParameterDescriptorBuilder::BuildParameterDescriptor( helper.IsFinal() ? Bool::True() : Bool::False()); Tag tag = ReadTag(); // read (first part of) initializer. - if (tag == kSomething) { + if ((tag == kSomething) && !function.is_abstract()) { // this will (potentially) read the initializer, but reset the position. Instance& constant = Instance::ZoneHandle( zone_, constant_evaluator_.EvaluateExpression(ReaderOffset())); - SkipExpression(); // read (actual) initializer. param_descriptor.SetAt(entry_start + Parser::kParameterDefaultValueOffset, constant); } else { param_descriptor.SetAt(entry_start + Parser::kParameterDefaultValueOffset, Object::null_instance()); } + if (tag == kSomething) { + SkipExpression(); // read (actual) initializer. + } if (FLAG_enable_mirrors && (helper.annotation_count_ > 0)) { AlternativeReadingScope alt(&reader_, param_kernel_offset); @@ -665,7 +667,7 @@ RawObject* BuildParameterDescriptor(const Function& function) { ExternalTypedData::Handle(zone, function.KernelData()), function.KernelDataProgramOffset(), &active_class); - return builder.BuildParameterDescriptor(function.kernel_offset()); + return builder.BuildParameterDescriptor(function); } else { return Thread::Current()->StealStickyError(); } diff --git a/tests/lib_2/mirrors/parameter_abstract_test.dart b/tests/lib_2/mirrors/parameter_abstract_test.dart index 298f5e9a21f..252d9e5222f 100644 --- a/tests/lib_2/mirrors/parameter_abstract_test.dart +++ b/tests/lib_2/mirrors/parameter_abstract_test.dart @@ -2,8 +2,6 @@ // 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. -// BOGUS: Note that both AST and bytecode modes are missing default values. - import 'dart:mirrors'; import 'package:expect/expect.dart'; @@ -23,12 +21,12 @@ main() { MethodMirror foo1 = cm.declarations[#foo1]; expect('Method(s(foo1) in s(C), abstract)', foo1); expect( - 'Parameter(s(x) in s(foo1), optional, named, value = Instance(value = 1), type = Class(s(int) in s(dart.core), top-level))', + 'Parameter(s(x) in s(foo1), optional, named, type = Class(s(int) in s(dart.core), top-level))', foo1.parameters[0]); expect( - 'Parameter(s(y) in s(foo1), optional, named, value = Instance(value = 2), type = Class(s(int) in s(dart.core), top-level))', + 'Parameter(s(y) in s(foo1), optional, named, type = Class(s(int) in s(dart.core), top-level))', foo1.parameters[1]); expect( - 'Parameter(s(z) in s(foo1), optional, named, value = Instance(value = 3), type = Class(s(int) in s(dart.core), top-level))', + 'Parameter(s(z) in s(foo1), optional, named, type = Class(s(int) in s(dart.core), top-level))', foo1.parameters[2]); } diff --git a/tests/lib_2/mirrors/stringify.dart b/tests/lib_2/mirrors/stringify.dart index b7268326f02..6ff5c3f52c2 100644 --- a/tests/lib_2/mirrors/stringify.dart +++ b/tests/lib_2/mirrors/stringify.dart @@ -175,7 +175,7 @@ String stringify(value) { throw 'Unexpected value: $value'; } -expect(expected, actual, [String reason]) { +expect(expected, actual, [String reason = ""]) { Expect.stringEquals(expected, stringify(actual), reason); }