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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/resolution/members.dart

Issue 23463032: Emit compile-time error on duplicate parameter names in typedefs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use defineElement for parameters. Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/co19/co19-dart2js.status » ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of resolution; 5 part of resolution;
6 6
7 abstract class TreeElements { 7 abstract class TreeElements {
8 Element get currentElement; 8 Element get currentElement;
9 Set<Node> get superUses; 9 Set<Node> get superUses;
10 10
(...skipping 1705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1716 return mapping[node] = element; 1716 return mapping[node] = element;
1717 } 1717 }
1718 1718
1719 DartType useType(TypeAnnotation annotation, DartType type) { 1719 DartType useType(TypeAnnotation annotation, DartType type) {
1720 if (type != null) { 1720 if (type != null) {
1721 mapping.setType(annotation, type); 1721 mapping.setType(annotation, type);
1722 useElement(annotation, type.element); 1722 useElement(annotation, type.element);
1723 } 1723 }
1724 return type; 1724 return type;
1725 } 1725 }
1726
1727 Element defineElement(Node node, Element element,
1728 {bool doAddToScope: true}) {
1729 compiler.ensure(element != null);
1730 mapping[node] = element;
1731 if (doAddToScope) {
1732 Element existing = scope.add(element);
1733 if (existing != element) {
1734 reportDuplicateDefinition(node, element, existing);
1735 }
1736 }
1737 return element;
1738 }
1739
1740 void reportDuplicateDefinition(name, Spannable definition,
ngeoffray 2013/09/16 16:12:49 Could you add (/* SourceString|Node */ name, ...)
1741 Spannable existing) {
1742 compiler.reportError(
1743 definition,
1744 MessageKind.DUPLICATE_DEFINITION, {'name': name});
1745 compiler.reportMessage(
1746 compiler.spanFromSpannable(existing),
1747 MessageKind.EXISTING_DEFINITION.error({'name': name}),
1748 Diagnostic.INFO);
1749 }
1726 } 1750 }
1727 1751
1728 /** 1752 /**
1729 * Core implementation of resolution. 1753 * Core implementation of resolution.
1730 * 1754 *
1731 * Do not subclass or instantiate this class outside this library 1755 * Do not subclass or instantiate this class outside this library
1732 * except for testing. 1756 * except for testing.
1733 */ 1757 */
1734 class ResolverVisitor extends MappingVisitor<Element> { 1758 class ResolverVisitor extends MappingVisitor<Element> {
1735 /** 1759 /**
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1908 DartType type = resolveTypeAnnotation(node); 1932 DartType type = resolveTypeAnnotation(node);
1909 if (type != null) { 1933 if (type != null) {
1910 if (inCheckContext) { 1934 if (inCheckContext) {
1911 compiler.enqueuer.resolution.registerIsCheck(type, mapping); 1935 compiler.enqueuer.resolution.registerIsCheck(type, mapping);
1912 } 1936 }
1913 return type.element; 1937 return type.element;
1914 } 1938 }
1915 return null; 1939 return null;
1916 } 1940 }
1917 1941
1918 Element defineElement(Node node, Element element,
1919 {bool doAddToScope: true}) {
1920 compiler.ensure(element != null);
1921 mapping[node] = element;
1922 if (doAddToScope) {
1923 Element existing = scope.add(element);
1924 if (existing != element) {
1925 compiler.reportError(
1926 node, MessageKind.DUPLICATE_DEFINITION, {'name': node});
1927 compiler.reportMessage(
1928 compiler.spanFromSpannable(existing),
1929 MessageKind.EXISTING_DEFINITION.error({'name': node}),
1930 Diagnostic.INFO);
1931 }
1932 }
1933 return element;
1934 }
1935
1936 bool isNamedConstructor(Send node) => node.receiver != null; 1942 bool isNamedConstructor(Send node) => node.receiver != null;
1937 1943
1938 Selector getRedirectingThisOrSuperConstructorSelector(Send node) { 1944 Selector getRedirectingThisOrSuperConstructorSelector(Send node) {
1939 if (isNamedConstructor(node)) { 1945 if (isNamedConstructor(node)) {
1940 SourceString constructorName = node.selector.asIdentifier().source; 1946 SourceString constructorName = node.selector.asIdentifier().source;
1941 return new Selector.callConstructor( 1947 return new Selector.callConstructor(
1942 constructorName, 1948 constructorName,
1943 enclosingElement.getLibrary()); 1949 enclosingElement.getLibrary());
1944 } else { 1950 } else {
1945 return new Selector.callDefaultConstructor( 1951 return new Selector.callDefaultConstructor(
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
2302 2308
2303 void resolveArguments(NodeList list) { 2309 void resolveArguments(NodeList list) {
2304 if (list == null) return; 2310 if (list == null) return;
2305 Map<SourceString, Node> seenNamedArguments = new Map<SourceString, Node>(); 2311 Map<SourceString, Node> seenNamedArguments = new Map<SourceString, Node>();
2306 for (Link<Node> link = list.nodes; !link.isEmpty; link = link.tail) { 2312 for (Link<Node> link = list.nodes; !link.isEmpty; link = link.tail) {
2307 Expression argument = link.head; 2313 Expression argument = link.head;
2308 visit(argument); 2314 visit(argument);
2309 NamedArgument namedArgument = argument.asNamedArgument(); 2315 NamedArgument namedArgument = argument.asNamedArgument();
2310 if (namedArgument != null) { 2316 if (namedArgument != null) {
2311 SourceString source = namedArgument.name.source; 2317 SourceString source = namedArgument.name.source;
2312 if (seenNamedArguments.containsKey(source)) { 2318 if (seenNamedArguments.containsKey(source)) {
ngeoffray 2013/09/16 16:12:49 Do you still need this check? It seems that the de
2313 compiler.reportError( 2319 reportDuplicateDefinition(
2320 source,
2314 argument, 2321 argument,
2315 MessageKind.DUPLICATE_DEFINITION, 2322 seenNamedArguments[source]);
2316 {'name': source});
2317 compiler.reportMessage(
2318 compiler.spanFromSpannable(seenNamedArguments[source]),
2319 MessageKind.EXISTING_DEFINITION.error({'name': source}),
2320 Diagnostic.INFO);
2321 } else { 2323 } else {
2322 seenNamedArguments[source] = namedArgument; 2324 seenNamedArguments[source] = namedArgument;
2323 } 2325 }
2324 } else if (!seenNamedArguments.isEmpty) { 2326 } else if (!seenNamedArguments.isEmpty) {
2325 error(argument, MessageKind.INVALID_ARGUMENT_AFTER_NAMED); 2327 error(argument, MessageKind.INVALID_ARGUMENT_AFTER_NAMED);
2326 } 2328 }
2327 } 2329 }
2328 } 2330 }
2329 2331
2330 visitSend(Send node) { 2332 visitSend(Send node) {
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
3326 TypedefResolverVisitor(Compiler compiler, 3328 TypedefResolverVisitor(Compiler compiler,
3327 TypedefElement typedefElement, 3329 TypedefElement typedefElement,
3328 TreeElementMapping mapping) 3330 TreeElementMapping mapping)
3329 : super(compiler, typedefElement, mapping); 3331 : super(compiler, typedefElement, mapping);
3330 3332
3331 visitTypedef(Typedef node) { 3333 visitTypedef(Typedef node) {
3332 TypedefType type = element.computeType(compiler); 3334 TypedefType type = element.computeType(compiler);
3333 scope = new TypeDeclarationScope(scope, element); 3335 scope = new TypeDeclarationScope(scope, element);
3334 resolveTypeVariableBounds(node.typeParameters); 3336 resolveTypeVariableBounds(node.typeParameters);
3335 3337
3336 element.functionSignature = SignatureResolver.analyze( 3338 FunctionSignature signature = SignatureResolver.analyze(
ngeoffray 2013/09/16 16:25:27 I would have thought that SignatureResolver would
3337 compiler, node.formals, node.returnType, element, 3339 compiler, node.formals, node.returnType, element,
3338 defaultValuesAllowed: false); 3340 defaultValuesAllowed: false);
3339 3341
3340 element.alias = compiler.computeFunctionType( 3342 scope = new MethodScope(scope, element);
3341 element, element.functionSignature); 3343 signature.forEachParameter((Element element) {
3344 defineElement(element.parseNode(compiler), element);
3345 });
3346
3347 element.alias = compiler.computeFunctionType(element, signature);
3342 3348
3343 // TODO(johnniwinther): Check for cyclic references in the typedef alias. 3349 // TODO(johnniwinther): Check for cyclic references in the typedef alias.
3344 } 3350 }
3345 } 3351 }
3346 3352
3347 /** 3353 /**
3348 * The implementation of [ResolverTask.resolveClass]. 3354 * The implementation of [ResolverTask.resolveClass].
3349 * 3355 *
3350 * This visitor has to be extra careful as it is building the basic 3356 * This visitor has to be extra careful as it is building the basic
3351 * element information, and cannot safely look at other elements as 3357 * element information, and cannot safely look at other elements as
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
4223 return e; 4229 return e;
4224 } 4230 }
4225 4231
4226 /// Assumed to be called by [resolveRedirectingFactory]. 4232 /// Assumed to be called by [resolveRedirectingFactory].
4227 Element visitReturn(Return node) { 4233 Element visitReturn(Return node) {
4228 Node expression = node.expression; 4234 Node expression = node.expression;
4229 return finishConstructorReference(visit(expression), 4235 return finishConstructorReference(visit(expression),
4230 expression, expression); 4236 expression, expression);
4231 } 4237 }
4232 } 4238 }
OLDNEW
« no previous file with comments | « no previous file | tests/co19/co19-dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698