mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:41:41 +00:00
2187286251
Fixes part of issue 32190. Change-Id: Iab0d304b4c77deb57c449788797300d38087466b Reviewed-on: https://dart-review.googlesource.com/47946 Reviewed-by: Siva Annamalai <asiva@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com>
108 lines
2.9 KiB
C++
108 lines
2.9 KiB
C++
// Copyright (c) 2017, 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.
|
|
|
|
#include "include/dart_api.h"
|
|
#include "vm/unit_test.h"
|
|
|
|
namespace dart {
|
|
|
|
#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
|
|
|
|
TEST_CASE(Mixin_PrivateSuperResolution) {
|
|
// clang-format off
|
|
Dart_SourceFile sourcefiles[] = {
|
|
{
|
|
"file:///test-app.dart",
|
|
"class A {\n"
|
|
" _bar() => 42;\n"
|
|
"}\n"
|
|
"class M extends A {\n"
|
|
" bar() => -1;\n"
|
|
"}\n"
|
|
"class B extends A {\n"
|
|
" foo() => 6;\n"
|
|
"}\n"
|
|
"class C extends B with M {\n"
|
|
" bar() => super._bar();\n"
|
|
"}\n"
|
|
"main() {\n"
|
|
" return new C().bar();\n"
|
|
"}\n",
|
|
},
|
|
{
|
|
"file:///.packages", "untitled:/"
|
|
}};
|
|
// clang-format on
|
|
|
|
Dart_Handle lib = TestCase::LoadTestScriptWithDFE(
|
|
sizeof(sourcefiles) / sizeof(Dart_SourceFile), sourcefiles,
|
|
/* resolver= */ NULL, /* finalize= */ true, /* incrementally= */ true);
|
|
EXPECT_VALID(lib);
|
|
Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
|
|
int64_t value = 0;
|
|
result = Dart_IntegerToInt64(result, &value);
|
|
EXPECT_VALID(result);
|
|
EXPECT_EQ(42, value);
|
|
}
|
|
|
|
TEST_CASE(Mixin_PrivateSuperResolutionCrossLibraryShouldFail) {
|
|
// clang-format off
|
|
Dart_SourceFile sourcefiles[] = {
|
|
{
|
|
"file:///test-app.dart",
|
|
"import 'test-lib.dart';\n"
|
|
"class D extends B with M {\n"
|
|
" bar() => super._bar();\n"
|
|
"}\n"
|
|
"main() {\n"
|
|
" try {\n"
|
|
" return new D().bar();\n"
|
|
" } catch (e) {\n"
|
|
" return e.toString().split('\\n').first;\n"
|
|
" }\n"
|
|
"}\n",
|
|
},
|
|
{
|
|
"file:///test-lib.dart",
|
|
"class A {\n"
|
|
" foo() => 4;\n"
|
|
" _bar() => 42;\n"
|
|
"}\n"
|
|
"class M extends A {\n"
|
|
" bar() => -1;\n"
|
|
"}\n"
|
|
"class B extends A {\n"
|
|
" foo() => 6;\n"
|
|
"}\n"
|
|
"class C extends B with M {\n"
|
|
" bar() => super._bar();\n"
|
|
"}\n"
|
|
},
|
|
{
|
|
"file:///.packages", "untitled:/"
|
|
}};
|
|
// clang-format on
|
|
|
|
Isolate* isolate = Isolate::Current();
|
|
Dart_Handle lib = TestCase::LoadTestScriptWithDFE(
|
|
sizeof(sourcefiles) / sizeof(Dart_SourceFile), sourcefiles,
|
|
/* resolver= */ NULL, /* finalize= */ true, /* incrementally= */ true);
|
|
if (isolate->strong()) {
|
|
EXPECT_ERROR(lib, "Error: Superclass has no method named '_bar'.");
|
|
} else {
|
|
EXPECT_VALID(lib);
|
|
Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
|
|
const char* result_str = NULL;
|
|
EXPECT(Dart_IsString(result));
|
|
EXPECT_VALID(Dart_StringToCString(result, &result_str));
|
|
EXPECT_STREQ(
|
|
"NoSuchMethodError: Super class of class 'D' has no instance method "
|
|
"'_bar'.",
|
|
result_str);
|
|
}
|
|
}
|
|
#endif // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
|
|
|
|
} // namespace dart
|