Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Issue 2904133002: Fix type inference of redirecting factory constructor invocations. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library fasta.body_builder; 5 library fasta.body_builder;
6 6
7 import '../fasta_codes.dart' 7 import '../fasta_codes.dart'
8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody;
9 9
10 import '../parser/parser.dart' show FormalParameterType, MemberKind, optional; 10 import '../parser/parser.dart' show FormalParameterType, MemberKind, optional;
(...skipping 1880 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 } else { 1891 } else {
1892 name = ""; 1892 name = "";
1893 } 1893 }
1894 push(type); 1894 push(type);
1895 push(typeArguments ?? NullValue.TypeArguments); 1895 push(typeArguments ?? NullValue.TypeArguments);
1896 push(name); 1896 push(name);
1897 } 1897 }
1898 1898
1899 @override 1899 @override
1900 Expression buildStaticInvocation(Member target, Arguments arguments, 1900 Expression buildStaticInvocation(Member target, Arguments arguments,
1901 {bool isConst: false, int charOffset: -1}) { 1901 {bool isConst: false, int charOffset: -1, Member initialTarget}) {
1902 List<TypeParameter> typeParameters = target.function.typeParameters; 1902 List<TypeParameter> typeParameters = target.function.typeParameters;
1903 if (target is Constructor) { 1903 if (target is Constructor) {
1904 assert(!target.enclosingClass.isAbstract); 1904 assert(!target.enclosingClass.isAbstract);
1905 typeParameters = target.enclosingClass.typeParameters; 1905 typeParameters = target.enclosingClass.typeParameters;
1906 } 1906 }
1907 if (!checkArguments(target.function, arguments, typeParameters)) { 1907 if (!checkArguments(target.function, arguments, typeParameters)) {
1908 return throwNoSuchMethodError(target.name.name, arguments, charOffset); 1908 return throwNoSuchMethodError(target.name.name, arguments, charOffset);
1909 } 1909 }
1910 if (target is Constructor) { 1910 if (target is Constructor) {
1911 return new KernelConstructorInvocation(target, arguments, 1911 return new KernelConstructorInvocation(target, initialTarget, arguments,
1912 isConst: isConst) 1912 isConst: isConst)
1913 ..fileOffset = charOffset; 1913 ..fileOffset = charOffset;
1914 } else if (target is Procedure && target.kind == ProcedureKind.Factory) { 1914 } else if (target is Procedure && target.kind == ProcedureKind.Factory) {
1915 return new KernelFactoryConstructorInvocation(target, arguments, 1915 return new KernelFactoryConstructorInvocation(
1916 target, initialTarget, arguments,
1916 isConst: isConst) 1917 isConst: isConst)
1917 ..fileOffset = charOffset; 1918 ..fileOffset = charOffset;
1918 } else { 1919 } else {
1919 return new KernelStaticInvocation(target, arguments, isConst: isConst) 1920 return new KernelStaticInvocation(target, arguments, isConst: isConst)
1920 ..fileOffset = charOffset; 1921 ..fileOffset = charOffset;
1921 } 1922 }
1922 } 1923 }
1923 1924
1924 @override 1925 @override
1925 bool checkArguments(FunctionNode function, Arguments arguments, 1926 bool checkArguments(FunctionNode function, Arguments arguments,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2003 2004
2004 if (typeArguments != null) { 2005 if (typeArguments != null) {
2005 assert(arguments.types.isEmpty); 2006 assert(arguments.types.isEmpty);
2006 KernelArguments.setExplicitArgumentTypes(arguments, typeArguments); 2007 KernelArguments.setExplicitArgumentTypes(arguments, typeArguments);
2007 } 2008 }
2008 2009
2009 String errorName; 2010 String errorName;
2010 if (type is ClassBuilder) { 2011 if (type is ClassBuilder) {
2011 Builder b = type.findConstructorOrFactory(name, token.charOffset, uri); 2012 Builder b = type.findConstructorOrFactory(name, token.charOffset, uri);
2012 Member target; 2013 Member target;
2014 Member initialTarget;
2013 if (b == null) { 2015 if (b == null) {
2014 // Not found. Reported below. 2016 // Not found. Reported below.
2015 } else if (b.isConstructor) { 2017 } else if (b.isConstructor) {
2018 initialTarget = b.target;
2016 if (type.isAbstract) { 2019 if (type.isAbstract) {
2017 push(evaluateArgumentsBefore( 2020 push(evaluateArgumentsBefore(
2018 arguments, 2021 arguments,
2019 buildAbstractClassInstantiationError( 2022 buildAbstractClassInstantiationError(
2020 type.name, nameToken.charOffset))); 2023 type.name, nameToken.charOffset)));
2021 return; 2024 return;
2022 } else { 2025 } else {
2023 target = b.target; 2026 target = initialTarget;
2024 } 2027 }
2025 } else if (b.isFactory) { 2028 } else if (b.isFactory) {
2026 target = getRedirectionTarget(b.target); 2029 initialTarget = b.target;
2030 target = getRedirectionTarget(initialTarget);
2027 if (target == null) { 2031 if (target == null) {
2028 push(buildCompileTimeError( 2032 push(buildCompileTimeError(
2029 "Cyclic definition of factory '${name}'.", 2033 "Cyclic definition of factory '${name}'.",
2030 nameToken.charOffset)); 2034 nameToken.charOffset));
2031 return; 2035 return;
2032 } 2036 }
2033 } 2037 }
2034 if (target is Constructor || 2038 if (target is Constructor ||
2035 (target is Procedure && target.kind == ProcedureKind.Factory)) { 2039 (target is Procedure && target.kind == ProcedureKind.Factory)) {
2036 push(buildStaticInvocation(target, arguments, 2040 push(buildStaticInvocation(target, arguments,
2037 isConst: optional("const", token), 2041 isConst: optional("const", token),
2038 charOffset: nameToken.charOffset)); 2042 charOffset: nameToken.charOffset,
2043 initialTarget: initialTarget));
2039 return; 2044 return;
2040 } else { 2045 } else {
2041 errorName = debugName(type.name, name); 2046 errorName = debugName(type.name, name);
2042 } 2047 }
2043 } else { 2048 } else {
2044 errorName = debugName(getNodeName(type), name); 2049 errorName = debugName(getNodeName(type), name);
2045 } 2050 }
2046 errorName ??= name; 2051 errorName ??= name;
2047 push(throwNoSuchMethodError(errorName, arguments, nameToken.charOffset)); 2052 push(throwNoSuchMethodError(errorName, arguments, nameToken.charOffset));
2048 }(); 2053 }();
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after
3192 if (starToken == null) { 3197 if (starToken == null) {
3193 return AsyncMarker.Async; 3198 return AsyncMarker.Async;
3194 } else { 3199 } else {
3195 assert(identical(starToken.stringValue, "*")); 3200 assert(identical(starToken.stringValue, "*"));
3196 return AsyncMarker.AsyncStar; 3201 return AsyncMarker.AsyncStar;
3197 } 3202 }
3198 } else { 3203 } else {
3199 return internalError("Unknown async modifier: $asyncToken"); 3204 return internalError("Unknown async modifier: $asyncToken");
3200 } 3205 }
3201 } 3206 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698