Files
sdk/tests/language/syntax/syntax_native_test.dart
T
William Hesse d6c9c9f8bf [test] Convert syntax_native_test to a static error test
Multitests of compile-time errors should be converted to static
error tests, so they don't run on runtime configurations.
Static error tests also test for all the static errors,
their positions, and error message, in a single test run.

This test is currently failing on the common front end,
and on all runtimes, and passing on the analyzer. The
change keeps the failure on common front end by adding
expectations for an error to be reported at the right places.

Bug: https://github.com/dart-lang/sdk/issues/54153
Change-Id: Ic64961f6e0e575ec60626d4f70a0fdc5d71d024e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363085
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: William Hesse <whesse@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2024-04-23 23:11:17 +00:00

56 lines
1.9 KiB
Dart

// Copyright (c) 2023, 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 DOMWindow {}
class Window extends DOMWindow native "*Window" {}
// ^^^^^^^^^^^^^^^^
// [analyzer] SYNTACTIC_ERROR.NATIVE_CLAUSE_IN_NON_SDK_CODE
// [cfe] expect cfe to report an error here
class Console native "=(typeof console == 'undefined' ? {} : console)" {}
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] SYNTACTIC_ERROR.NATIVE_CLAUSE_IN_NON_SDK_CODE
// [cfe] expect cfe to report an error here
class NativeClass native "FooBar" {}
// ^^^^^^^^^^^^^^^
// [analyzer] SYNTACTIC_ERROR.NATIVE_CLAUSE_IN_NON_SDK_CODE
// [cfe] expect cfe to report an error here
abstract class Fisk {}
class BoolImplementation implements Fisk native "Boolean" {}
// ^^^^^^^^^^^^^^^^
// [analyzer] SYNTACTIC_ERROR.NATIVE_CLAUSE_IN_NON_SDK_CODE
// [cfe] expect cfe to report an error here
class _JSON native 'JSON' {}
// ^^^^^^^^^^^^^
// [analyzer] SYNTACTIC_ERROR.NATIVE_CLAUSE_IN_NON_SDK_CODE
// [cfe] expect cfe to report an error here
class ListFactory<E> implements List<E> native "Array" {
// ^^^^^^^^^^^^^^
// [analyzer] SYNTACTIC_ERROR.NATIVE_CLAUSE_IN_NON_SDK_CODE
// [cfe] expect cfe to report an error here
noSuchMethod(_) => null; // Allow unimplemented methods
}
main() {
try {
new Window();
new Console();
new NativeClass();
new BoolImplementation();
new _JSON();
new ListFactory();
new ListFactory<Object>();
} catch (ex) {
// Swallowing exceptions. Any error should be a compile-time error
// which kills the current isolate.
}
throw 'This test should fail to compile, not throw a run-time error.';
}