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:
ngeoffray@google.com 2013-05-22 09:17:49 +00:00
parent e471a85e0f
commit 78fcea3753
2 changed files with 26 additions and 1 deletions

View file

@ -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.

View 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());
}
}