dart-sdk/tests/language/inference_update_2/no_such_method_restriction_disabled_lib.dart
Paul Berry 54906759b9 Don't delegate foreign private names to noSuchMethod.
If a concrete class implements an interface containing a name that's
private to a different library, any attempt to invoke that name will
result in an exception getting thrown.  Previously, such attempts
would result in the call being diverted to noSuchMethod.

This change closes a loophole in Dart's privacy system, and paves the way for
a future implementation of promotion for private final fields (see
https://github.com/dart-lang/language/issues/2020).

Bug: https://github.com/dart-lang/sdk/issues/49687
Change-Id: Ie55805e0fc77dc39713761a80a42c28bd0504722
Tested: language tests
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/255640
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2022-09-27 21:20:35 +00:00

104 lines
2.3 KiB
Dart

// Copyright (c) 2022, 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.
// Library used by `no_such_method_restriction_disabled_test.dart`.
// @dart=2.17
class Interface {
static int interfaceCount = 0;
int _privateField = 100;
int get _privateGetter {
interfaceCount++;
return 101;
}
set _privateSetter(int value) {
interfaceCount++;
}
int _privateMethod() {
interfaceCount++;
return 102;
}
int publicField = 103;
int get publicGetter {
interfaceCount++;
return 104;
}
set publicSetter(int value) {
interfaceCount++;
}
int publicMethod() {
interfaceCount++;
return 105;
}
static int getPrivateField(Interface x) => x._privateField;
static void setPrivateField(Interface x) => x._privateField = 106;
static int callPrivateGetter(Interface x) => x._privateGetter;
static void callPrivateSetter(Interface x) => x._privateSetter = 107;
static int callPrivateMethod(Interface x) => x._privateMethod();
static int getPublicField(Interface x) => x.publicField;
static void setPublicField(Interface x) => x.publicField = 108;
static int callPublicGetter(Interface x) => x.publicGetter;
static void callPublicSetter(Interface x) => x.publicSetter = 109;
static int callPublicMethod(Interface x) => x.publicMethod();
}
class Dynamic {
static int getPrivateField(dynamic x) => x._privateField;
static void setPrivateField(dynamic x) => x._privateField = 103;
static int callPrivateGetter(dynamic x) => x._privateGetter;
static void callPrivateSetter(dynamic x) => x._privateSetter = 104;
static int callPrivateMethod(dynamic x) => x._privateMethod();
static int getPublicField(dynamic x) => x.publicField;
static void setPublicField(dynamic x) => x.publicField = 108;
static int callPublicGetter(dynamic x) => x.publicGetter;
static void callPublicSetter(dynamic x) => x.publicSetter = 109;
static int callPublicMethod(dynamic x) => x.publicMethod();
}
class Nsm {
int otherNsmCount = 0;
@override
noSuchMethod(Invocation invocation) {
return otherNsmCount++;
}
}
class Stubs implements Interface {
int stubsNsmCount = 0;
@override
noSuchMethod(Invocation invocation) {
return stubsNsmCount++;
}
}