mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
Add check for constness in constructor redirection
Const constructor can only redirect to another const constructor. BUG=#27617 R=regis@google.com Review URL: https://codereview.chromium.org/2439593003 .
This commit is contained in:
parent
16db33b7a2
commit
f73ea62c99
|
@ -3116,7 +3116,13 @@ void Parser::ParseConstructorRedirection(const Class& cls,
|
|||
const Function& redirect_ctor = Function::ZoneHandle(Z,
|
||||
cls.LookupConstructor(ctor_name));
|
||||
if (redirect_ctor.IsNull()) {
|
||||
ReportError(call_pos, "constructor '%s' not found", ctor_name.ToCString());
|
||||
ReportError(call_pos, "constructor '%s' not found",
|
||||
String::Handle(Z, redirect_ctor.UserVisibleName()).ToCString());
|
||||
}
|
||||
if (current_function().is_const() && !redirect_ctor.is_const()) {
|
||||
ReportError(call_pos,
|
||||
"redirection constructor '%s' must be const",
|
||||
String::Handle(Z, redirect_ctor.UserVisibleName()).ToCString());
|
||||
}
|
||||
String& error_message = String::Handle(Z);
|
||||
if (!redirect_ctor.AreValidArguments(arguments->length(),
|
||||
|
@ -3124,7 +3130,7 @@ void Parser::ParseConstructorRedirection(const Class& cls,
|
|||
&error_message)) {
|
||||
ReportError(call_pos,
|
||||
"invalid arguments passed to constructor '%s': %s",
|
||||
ctor_name.ToCString(),
|
||||
String::Handle(Z, redirect_ctor.UserVisibleName()).ToCString(),
|
||||
error_message.ToCString());
|
||||
}
|
||||
current_block_->statements->Add(
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
[ $compiler == dart2analyzer ]
|
||||
|
||||
regress_26668_test: Fail # Issue 26678
|
||||
regress_27617_test/1: MissingCompileTimeError
|
||||
|
||||
# Runtime negative test. No static errors or warnings.
|
||||
closure_call_wrong_argument_count_negative_test: skip
|
||||
|
|
16
tests/language/regress_27617_test.dart
Normal file
16
tests/language/regress_27617_test.dart
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
|
||||
|
||||
class Foo {
|
||||
final String greeting;
|
||||
Foo._(this.greeting) { }
|
||||
|
||||
// Const constructor must not redirect to non-const constructor.
|
||||
const Foo.hi() : this._('hi'); /// 1: compile-time error
|
||||
}
|
||||
|
||||
main() {
|
||||
const h = const Foo.hi(); /// 1: continued
|
||||
}
|
Loading…
Reference in a new issue