dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.21k stars 1.57k forks source link

analyzer accepts string r'\n', which is an error. #28664

Open eernstg opened 7 years ago

eernstg commented 7 years ago

The test tests/language/bad_raw_string_negative_test.dart includes a raw string containing a new line, and this cannot be derived from stringLiteral in the language specification, so it should be a syntax error.

Currently (Feb 7, 2017), we get this:

...$ dartanalyzer tests/language/bad_raw_string_negative_test.dart
Analyzing [tests/language/bad_raw_string_negative_test.dart]...
No issues found
...$ dartanalyzer --version
dartanalyzer version 1.22.0-dev.10.3
eernstg commented 7 years ago

Surprisingly, the buildbot analyzer-win7-release-be in build 2617 reports the expected syntax error, and the test is considered to be failing:

FAILED: dart2analyzer-none release_x64 language/bad_raw_string_negative_test
Expected: Pass 
Actual: CompileTimeError
CommandOutput[dart2analyzer]:

stderr:
ERROR|SYNTACTIC_ERROR|UNTERMINATED_STRING_LITERAL|E:\\b\\build\\slave\\analyzer-win7-release-be\\build\\sdk\\tests\\language\\bad_raw_string_negative_test.dart|7|12|1|Unterminated string literal.
ERROR|SYNTACTIC_ERROR|UNTERMINATED_STRING_LITERAL|E:\\b\\build\\slave\\analyzer-win7-release-be\\build\\sdk\\tests\\language\\bad_raw_string_negative_test.dart|7|16|1|Unterminated string literal.
ERROR|SYNTACTIC_ERROR|EXPECTED_TOKEN|E:\\b\\build\\slave\\analyzer-win7-release-be\\build\\sdk\\tests\\language\\bad_raw_string_negative_test.dart|8|1|1|Expected to find ';'.
ERROR|SYNTACTIC_ERROR|EXPECTED_TOKEN|E:\\b\\build\\slave\\analyzer-win7-release-be\\build\\sdk\\tests\\language\\bad_raw_string_negative_test.dart|8|1|1|Expected to find ')'.

So test.py on the buildbot analyzer-win7-release-be considers the test to fail when it has a compile-time error even though its name is '*_negative_test.dart', and on analyzer-linux-release-be we get this:

Done dart2analyzer-none release_x64 language/bad_raw_string_negative_test: pass

where a local test confirms that dartanalizer runs without emitting any error messages.

Given that this seems to involve both the testing infrastructure and the analyzer, I've removed the 'area-' label.

whesse commented 7 years ago

If we add another newline inside the string, then the test fails on linux as well.

Compiler commands that fail ignore the "isNegative" state when returning their output. I will fix this, but this might break other tests, that are called _negative_test but only fail at runtime, not compilation.

There is no "isNegative" flag that can be put in the comments, or "compilationError" that can be put in the comments, because those flags are only in co19 tests.

whesse commented 7 years ago

I have made this test into a multitest called bad_raw_string_test.dart, and included a test like the current one for the case of a raw string with a single character, which is a newline, which fails to produce a compile time error on linux and mac. Marking it in the status file with this issue, which I have renamed.