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

Side by Side Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 1531313002: fix #25280, treat setters as returning void in strong mode (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 analyzer.test.generated.resolver_test; 5 library analyzer.test.generated.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 13492 matching lines...) Expand 10 before | Expand all | Expand 10 after
13503 _resolveTestUnit(code); 13503 _resolveTestUnit(code);
13504 13504
13505 SimpleIdentifier identifier = _findIdentifier('foo'); 13505 SimpleIdentifier identifier = _findIdentifier('foo');
13506 VariableDeclaration declaration = 13506 VariableDeclaration declaration =
13507 identifier.getAncestor((node) => node is VariableDeclaration); 13507 identifier.getAncestor((node) => node is VariableDeclaration);
13508 13508
13509 expect(declaration.initializer.staticType.toString(), "Future<String>"); 13509 expect(declaration.initializer.staticType.toString(), "Future<String>");
13510 expect(declaration.initializer.propagatedType, isNull); 13510 expect(declaration.initializer.propagatedType, isNull);
13511 } 13511 }
13512 13512
13513 void test_setterWithDynamicTypeIsError() {
13514 Source source = addSource(r'''
13515 class A {
13516 dynamic set f(String s) => null;
13517 }
13518 dynamic set g(int x) => null;
13519 ''');
13520 computeLibrarySourceErrors(source);
13521 assertErrors(source, [
13522 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER,
13523 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER
13524 ]);
13525 verify([source]);
13526 }
13527
13528 void test_setterWithExplicitVoidType_returningVoid() {
13529 Source source = addSource(r'''
13530 void returnsVoid() {}
13531 class A {
13532 void set f(String s) => returnsVoid();
13533 }
13534 void set g(int x) => returnsVoid();
13535 ''');
13536 computeLibrarySourceErrors(source);
13537 assertNoErrors(source);
13538 verify([source]);
13539 }
13540
13541 void test_setterWithNoVoidType() {
13542 Source source = addSource(r'''
13543 class A {
13544 set f(String s) {
13545 return '42';
13546 }
13547 }
13548 set g(int x) => 42;
13549 ''');
13550 computeLibrarySourceErrors(source);
13551 assertErrors(source, [
13552 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
13553 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE
13554 ]);
13555 verify([source]);
13556 }
13557
13558 void test_setterWithNoVoidType_returningVoid() {
13559 Source source = addSource(r'''
13560 void returnsVoid() {}
13561 class A {
13562 set f(String s) => returnsVoid();
13563 }
13564 set g(int x) => returnsVoid();
13565 ''');
13566 computeLibrarySourceErrors(source);
13567 assertNoErrors(source);
13568 verify([source]);
13569 }
13570
13571 void test_setterWithOtherTypeIsError() {
13572 Source source = addSource(r'''
13573 class A {
13574 String set f(String s) => null;
13575 }
13576 Object set g(x) => null;
13577 ''');
13578 computeLibrarySourceErrors(source);
13579 assertErrors(source, [
13580 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER,
13581 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER
13582 ]);
13583 verify([source]);
13584 }
13585
13513 void test_ternaryOperator_null_left() { 13586 void test_ternaryOperator_null_left() {
13514 String code = r''' 13587 String code = r'''
13515 main() { 13588 main() {
13516 var foo = (true) ? null : 3; 13589 var foo = (true) ? null : 3;
13517 } 13590 }
13518 '''; 13591 ''';
13519 _resolveTestUnit(code); 13592 _resolveTestUnit(code);
13520 13593
13521 SimpleIdentifier identifier = _findIdentifier('foo'); 13594 SimpleIdentifier identifier = _findIdentifier('foo');
13522 VariableDeclaration declaration = 13595 VariableDeclaration declaration =
(...skipping 2856 matching lines...) Expand 10 before | Expand all | Expand 10 after
16379 16452
16380 void _resolveTestUnit(String code) { 16453 void _resolveTestUnit(String code) {
16381 testCode = code; 16454 testCode = code;
16382 testSource = addSource(testCode); 16455 testSource = addSource(testCode);
16383 LibraryElement library = resolve2(testSource); 16456 LibraryElement library = resolve2(testSource);
16384 assertNoErrors(testSource); 16457 assertNoErrors(testSource);
16385 verify([testSource]); 16458 verify([testSource]);
16386 testUnit = resolveCompilationUnit(testSource, library); 16459 testUnit = resolveCompilationUnit(testSource, library);
16387 } 16460 }
16388 } 16461 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/all_the_rest_test.dart ('k') | pkg/analyzer/test/src/summary/summary_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698