mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 17:15:02 +00:00
Specialize the return type of a factory constructor to be the enclosing type.
R=karlklose@google.com Review URL: https://codereview.chromium.org//15712002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@22999 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
e471a85e0f
commit
78fcea3753
|
@ -3743,7 +3743,9 @@ class SignatureResolver extends CommonResolverVisitor<Element> {
|
|||
requiredParameterCount = parametersBuilder.length;
|
||||
parameters = parametersBuilder.toLink();
|
||||
}
|
||||
DartType returnType = compiler.resolveReturnType(element, returnNode);
|
||||
DartType returnType = element.isFactoryConstructor()
|
||||
? element.getEnclosingClass().computeType(compiler)
|
||||
: compiler.resolveReturnType(element, returnNode);
|
||||
if (element.isSetter() && (requiredParameterCount != 1 ||
|
||||
visitor.optionalParameterCount != 0)) {
|
||||
// If there are no formal parameters, we already reported an error above.
|
||||
|
|
23
tests/language/factory_return_type_checked_test.dart
Normal file
23
tests/language/factory_return_type_checked_test.dart
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
class A {
|
||||
factory A() => 42;
|
||||
}
|
||||
|
||||
main() {
|
||||
bool isCheckedMode = false;
|
||||
try {
|
||||
String a = 42;
|
||||
} catch (e) {
|
||||
isCheckedMode = true;
|
||||
}
|
||||
if (isCheckedMode) {
|
||||
Expect.throws(() => new A(), (e) => e is TypeError);
|
||||
} else {
|
||||
Expect.equals(42, new A());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue