diff --git a/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart b/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart index 6a8cdc1df53..fb9368f94d9 100644 --- a/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart +++ b/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart @@ -123,6 +123,24 @@ FastaMessage _formatFactoryNotSync(Uri uri, int charOffset) { arguments: {}); } +// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. +const FastaCode<_SuperNullAware> codeSuperNullAware = + const FastaCode<_SuperNullAware>("SuperNullAware", + template: r"'super' can't be null.", + tip: r"Try replacing '?.' with '.'", + dart2jsCode: "FASTA_IGNORED", + format: _formatSuperNullAware); + +typedef FastaMessage _SuperNullAware(Uri uri, int charOffset); + +// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. +FastaMessage _formatSuperNullAware(Uri uri, int charOffset) { + return new FastaMessage(uri, charOffset, codeSuperNullAware, + message: "'super' can't be null.", + tip: "Try replacing '?.' with '.'", + arguments: {}); +} + // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. const FastaCode<_PrivateNamedParameter> codePrivateNamedParameter = const FastaCode<_PrivateNamedParameter>("PrivateNamedParameter", diff --git a/pkg/front_end/lib/src/fasta/kernel/fasta_accessors.dart b/pkg/front_end/lib/src/fasta/kernel/fasta_accessors.dart index 8f95551f68b..324352bb020 100644 --- a/pkg/front_end/lib/src/fasta/kernel/fasta_accessors.dart +++ b/pkg/front_end/lib/src/fasta/kernel/fasta_accessors.dart @@ -331,6 +331,10 @@ class ThisAccessor extends FastaAccessor { buildPropertyAccess( IncompleteSend send, int operatorOffset, bool isNullAware) { if (isInitializer && send is SendAccessor) { + if (isNullAware) { + helper.addCompileTimeError( + operatorOffset, "Expected '.'\nTry removing '?'."); + } return buildConstructorInitializer( offsetForToken(send.token), send.name, send.arguments); } @@ -484,6 +488,12 @@ class SendAccessor extends IncompleteSend { } if (receiver is PrefixBuilder) { PrefixBuilder prefix = receiver; + if (isNullAware) { + helper.addCompileTimeError( + offsetForToken(token), + "Library prefix '${prefix.name}' can't be used with null-aware " + "operator.\nTry removing '?'."); + } receiver = helper.scopeLookup(prefix.exports, name.name, token, isQualified: true, prefix: prefix); return helper.finishSend(receiver, arguments, offsetForToken(token)); @@ -544,6 +554,12 @@ class IncompletePropertyAccessor extends IncompleteSend { } if (receiver is PrefixBuilder) { PrefixBuilder prefix = receiver; + if (isNullAware) { + helper.addCompileTimeError( + offsetForToken(token), + "Library prefix '${prefix.name}' can't be used with null-aware " + "operator.\nTry removing '?'."); + } return helper.scopeLookup(prefix.exports, name.name, token, isQualified: true, prefix: prefix); } diff --git a/pkg/front_end/lib/src/fasta/parser/parser.dart b/pkg/front_end/lib/src/fasta/parser/parser.dart index 61e9506ee85..deb86f89dd8 100644 --- a/pkg/front_end/lib/src/fasta/parser/parser.dart +++ b/pkg/front_end/lib/src/fasta/parser/parser.dart @@ -51,6 +51,7 @@ import '../fasta_codes.dart' codeRequiredParameterWithDefault, codeSetterNotSync, codeStackOverflow, + codeSuperNullAware, codeTypeAfterVar, codeTypeRequired, codeUnexpectedToken, @@ -3057,6 +3058,8 @@ class Parser { listener.handleNoTypeArguments(token); token = parseArguments(token); listener.endSend(beginToken, token); + } else if (optional("?.", token)) { + reportRecoverableErrorCode(token, codeSuperNullAware); } return token; } diff --git a/pkg/front_end/messages.yaml b/pkg/front_end/messages.yaml index f441bcc7c50..90d716e914a 100644 --- a/pkg/front_end/messages.yaml +++ b/pkg/front_end/messages.yaml @@ -429,3 +429,8 @@ CatchSyntax: template: "'catch' must be followed by '(identifier)' or '(identifier, identifier)'." tip: "No types are needed, the first is given by 'on', the second is always 'StackTrace'." dart2jsCode: FASTA_IGNORED + +SuperNullAware: + template: "'super' can't be null." + tip: "Try replacing '?.' with '.'" + dart2jsCode: FASTA_IGNORED diff --git a/tests/language/language_kernel.status b/tests/language/language_kernel.status index b364051a6a1..a7ba772711c 100644 --- a/tests/language/language_kernel.status +++ b/tests/language/language_kernel.status @@ -342,11 +342,6 @@ type_variable_bounds4_test/01: RuntimeError [ $compiler == dartk || $compiler == dartkp ] compile_time_constant_test/01: MissingCompileTimeError # Fixed in ahe's dev branch. -conditional_method_invocation_test/11: MissingCompileTimeError # Fixed in ahe's dev branch. -conditional_property_access_test/09: MissingCompileTimeError # Fixed in ahe's dev branch. -conditional_property_assignment_test/20: MissingCompileTimeError # Fixed in ahe's dev branch. -conditional_property_assignment_test/21: MissingCompileTimeError # Fixed in ahe's dev branch. -conditional_property_assignment_test/22: MissingCompileTimeError # Fixed in ahe's dev branch. const_constructor_mixin2_test/01: MissingCompileTimeError # Fixed in ahe's dev branch. const_constructor_mixin3_test/01: MissingCompileTimeError # Fixed in ahe's dev branch. const_constructor_mixin_test/01: MissingCompileTimeError # Fixed in ahe's dev branch. @@ -413,23 +408,6 @@ ref_before_declaration_test/06: MissingCompileTimeError # Fixed in ahe's dev bra ref_before_declaration_test/07: MissingCompileTimeError # Fixed in ahe's dev branch. regress_29349_test: CompileTimeError # Fixed in ahe's dev branch. scope_variable_test/01: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/01: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/02: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/03: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/04: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/05: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/06: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/07: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/08: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/09: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/10: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/11: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/12: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/13: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/14: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/15: MissingCompileTimeError # Fixed in ahe's dev branch. -super_conditional_operator_test/16: MissingCompileTimeError # Fixed in ahe's dev branch. -this_conditional_operator_test/01: MissingCompileTimeError # Fixed in ahe's dev branch. [ $unchecked && ($compiler == dartk || $compiler == dartkp) ] const_conditional_test/08: MissingCompileTimeError # KernelVM bug: Constant evaluation.