Skip to content

Commit

Permalink
Check for conflicts between a static setter and a constructor or stat…
Browse files Browse the repository at this point in the history
…ic method.

Bug: #33237
Change-Id: I44c69f32039de9b024c942706e96bf1998217350
Reviewed-on: https://dart-review.googlesource.com/60583
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Kevin Millikin <kmillikin@google.com>
  • Loading branch information
askeksa authored and commit-bot@chromium.org committed Jun 28, 2018
1 parent b0cbc4e commit 90e27b1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/front_end/lib/src/fasta/source/source_class_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ class SourceClassBuilder extends KernelClassBuilder {

scope.setters.forEach((String name, Declaration setter) {
Declaration member = scopeBuilder[name];
if (member == null || !member.isField || member.isFinal) return;
if (member == null ||
!(member.isField && !member.isFinal ||
member.isRegularMethod && member.isStatic && setter.isStatic))
return;
if (member.isInstanceMember == setter.isInstanceMember) {
addProblem(templateConflictsWithMember.withArguments(name),
setter.charOffset, noLength);
Expand All @@ -194,6 +197,15 @@ class SourceClassBuilder extends KernelClassBuilder {
}
});

scope.setters.forEach((String name, Declaration setter) {
Declaration constructor = constructorScopeBuilder[name];
if (constructor == null || !setter.isStatic) return;
addProblem(templateConflictsWithConstructor.withArguments(name),
setter.charOffset, noLength);
addProblem(templateConflictsWithSetter.withArguments(name),
constructor.charOffset, noLength);
});

cls.procedures.sort(compareProcedures);
return cls;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/co19/co19-kernel.status
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ Language/Classes/Setters/same_name_getter_different_type_t02: CompileTimeError
Language/Classes/Setters/type_object_t01: CompileTimeError
Language/Classes/Setters/type_object_t02: CompileTimeError
Language/Classes/Static_Methods/declaration_t03: CompileTimeError
Language/Classes/Static_Methods/same_name_method_and_setter_t01: CompileTimeError # Invalid test, see #33237
Language/Classes/Static_Methods/type_object_t01: CompileTimeError
Language/Classes/Static_Methods/type_object_t02: CompileTimeError
Language/Classes/Static_Variables/inheritance_t01: CompileTimeError
Expand Down Expand Up @@ -1692,6 +1693,7 @@ Language/Classes/Constructors/Generative_Constructors/superclass_constructor_t05
Language/Classes/Constructors/Generative_Constructors/superclass_constructor_t06: MissingCompileTimeError
Language/Classes/Instance_Variables/constant_t01: MissingCompileTimeError
Language/Classes/Static_Methods/declaration_t01: MissingCompileTimeError
Language/Classes/Static_Methods/same_name_method_and_setter_t01: CompileTimeError # Invalid test, see #33237
Language/Classes/Superclasses/wrong_superclass_t08: MissingCompileTimeError
Language/Classes/Superinterfaces/wrong_type_t05: MissingCompileTimeError
Language/Classes/same_name_instance_and_static_members_t01: MissingCompileTimeError
Expand Down
8 changes: 8 additions & 0 deletions tests/language_2/language_2_analyzer.status
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ setter_declaration2_negative_test: CompileTimeError
setter_declaration_negative_test: CompileTimeError
source_self_negative_test: CompileTimeError
static_call_wrong_argument_count_negative_test: Fail # Issue 12156
static_setter_conflicts_test/02: MissingCompileTimeError
static_setter_conflicts_test/11: MissingCompileTimeError
static_setter_conflicts_test/12: MissingCompileTimeError
string_escape4_negative_test: CompileTimeError
string_interpolate1_negative_test: CompileTimeError
string_interpolate2_negative_test: CompileTimeError
Expand Down Expand Up @@ -1111,6 +1114,11 @@ implicit_creation/implicit_new_prefix_constructor_named_test: CompileTimeError
implicit_creation/implicit_new_prefix_constructor_test: CompileTimeError
type_literal_prefix_call_test: CompileTimeError

[ $compiler == dart2analyzer && !$preview_dart_2 && !$strong]
static_setter_conflicts_test/01: MissingCompileTimeError
static_setter_conflicts_test/04: MissingCompileTimeError
static_setter_conflicts_test/07: MissingCompileTimeError

[ $compiler == dart2analyzer && $strong ]
accessor_conflict_export2_test: CompileTimeError # Issue 25626
accessor_conflict_export_test: CompileTimeError # Issue 25626
Expand Down
3 changes: 3 additions & 0 deletions tests/language_2/language_2_dartdevc.status
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ regress_30339_test: CompileTimeError # As expected. Should we make this a multi
reify_typevar_static_test/00: MissingCompileTimeError # Issue 29920
setter_override2_test/02: MissingCompileTimeError # Issue 14736
stacktrace_test: RuntimeError # Issue 29920
static_setter_conflicts_test/02: MissingCompileTimeError
static_setter_conflicts_test/11: MissingCompileTimeError
static_setter_conflicts_test/12: MissingCompileTimeError
string_split_test: CompileTimeError
string_supertype_checked_test: CompileTimeError
super_bound_closure_test/none: CompileTimeError
Expand Down
4 changes: 4 additions & 0 deletions tests/language_2/language_2_kernel.status
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,10 @@ static_final_field2_test/01: MissingCompileTimeError
static_getter_no_setter1_test/01: MissingCompileTimeError
static_getter_no_setter2_test/01: MissingCompileTimeError
static_initializer_type_error_test: MissingCompileTimeError
static_setter_conflicts_test/01: MissingCompileTimeError
static_setter_conflicts_test/03: MissingCompileTimeError
static_setter_conflicts_test/04: MissingCompileTimeError
static_setter_conflicts_test/07: MissingCompileTimeError
static_setter_get_test/01: MissingCompileTimeError
string_interpolation_test/01: MissingCompileTimeError
string_no_operator_test/01: MissingCompileTimeError
Expand Down
26 changes: 26 additions & 0 deletions tests/language_2/static_setter_conflicts_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2018, 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.

class C {
static set foo(int x) {}

int foo(int x) => x; //# 01: compile-time error
static int foo(int x) => x; //# 02: compile-time error

int foo = 3; //# 03: compile-time error
final int foo = 4; //# 04: compile-time error
static int foo = 5; //# 05: compile-time error
static final int foo = 6; //# 06: ok

int get foo => 7; //# 07: compile-time error
static int get foo => 8; //# 08: ok

set foo(int x) {} //# 09: compile-time error
static set foo(int x) {} //# 10: compile-time error

C.foo(int x) {} //# 11: compile-time error
factory C.foo(int x) => null; //# 12: compile-time error
}

main() {}

0 comments on commit 90e27b1

Please sign in to comment.