Skip to content

Commit

Permalink
Version 3.5.0-268.0.dev
Browse files Browse the repository at this point in the history
Merge 627cd30 into dev
  • Loading branch information
Dart CI committed Jun 15, 2024
2 parents fd8f26d + 627cd30 commit f009db7
Show file tree
Hide file tree
Showing 99 changed files with 4,623 additions and 3,236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class OverrideHelper {
var element = interfaceMap[name];
// Gracefully degrade if the overridden element has not been resolved.
if (element != null) {
if (_hasNonVirtualAnnotation(element)) {
continue;
}

var invokeSuper = interface.isSuperImplemented(name);
var matcherScore = math.max(
math.max(state.matcher.score('override'),
Expand All @@ -63,6 +67,17 @@ class OverrideHelper {
}
}

/// Checks if the [element] has the `@nonVirtual` annotation.
bool _hasNonVirtualAnnotation(ExecutableElement element) {
if (element is PropertyAccessorElement && element.isSynthetic) {
var variable = element.variable2;
if (variable != null && variable.hasNonVirtual) {
return true;
}
}
return element.hasNonVirtual;
}

/// Return the list of names that belong to the [interface] of a class, but
/// are not yet declared in the class.
List<Name> _namesToOverride(Uri libraryUri, Interface interface) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ mixin OverrideTestCases on AbstractCompletionDriverTest {
@override
Future<void> setUp() async {
await super.setUp();
writeTestPackageConfig(meta: true);

printerConfiguration = printer.Configuration(
filter: (suggestion) {
Expand Down Expand Up @@ -1236,6 +1237,37 @@ class A {
void foo01() {}
}
class B extends A {
@override
foo^
}
''');

assertResponse(r'''
replacement
left: 3
suggestions
void foo01() {
// TODO: implement foo01
super.foo01();
}
kind: override
displayText: foo01() { … }
selection: 48 14
''');
}

Future<void> test_class_method_fromExtends_withOverride_nonVirtual() async {
await computeSuggestions('''
import 'package:meta/meta.dart';
class A {
void foo01() {}
@nonVirtual
void foo02() {}
}
class B extends A {
@override
foo^
Expand Down
11 changes: 9 additions & 2 deletions pkg/front_end/lib/src/fasta/builder/record_type_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ abstract class RecordTypeBuilderImpl extends RecordTypeBuilder {
positionalEntries.add(type);
String? fieldName = field.name;
if (fieldName != null) {
if (library is SourceLibraryBuilder && field.isWildcard) {
continue;
}
if (fieldName.startsWith("_")) {
library.addProblem(messageRecordFieldsCantBePrivate,
field.charOffset, fieldName.length, fileUri);
Expand Down Expand Up @@ -380,7 +383,10 @@ class RecordTypeFieldBuilder {

final int charOffset;

RecordTypeFieldBuilder(this.metadata, this.type, this.name, this.charOffset);
final bool isWildcard;

RecordTypeFieldBuilder(this.metadata, this.type, this.name, this.charOffset,
{this.isWildcard = false});

RecordTypeFieldBuilder clone(
List<NamedTypeBuilder> newTypes,
Expand All @@ -392,7 +398,8 @@ class RecordTypeFieldBuilder {
metadata,
type.clone(newTypes, contextLibrary, contextDeclaration),
name,
charOffset);
charOffset,
isWildcard: isWildcard);
}

@override
Expand Down
16 changes: 12 additions & 4 deletions pkg/front_end/lib/src/fasta/kernel/body_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5213,13 +5213,17 @@ class BodyBuilder extends StackListenerImpl
Object? type = pop();
// TODO(johnniwinther): How should we handle annotations?
pop(NullValues.Metadata); // Annotations.

String? fieldName = name is Identifier ? name.name : null;
push(new RecordTypeFieldBuilder(
[],
type is ParserRecovery
? new InvalidTypeBuilderImpl(uri, type.charOffset)
: type as TypeBuilder,
name is Identifier ? name.name : null,
name is Identifier ? name.nameOffset : TreeNode.noOffset));
fieldName,
name is Identifier ? name.nameOffset : TreeNode.noOffset,
isWildcard:
libraryFeatures.wildcardVariables.isEnabled && fieldName == '_'));
}

@override
Expand Down Expand Up @@ -7207,7 +7211,9 @@ class BodyBuilder extends StackListenerImpl
VariableDeclaration variable = new VariableDeclarationImpl(name.name,
forSyntheticToken: nameToken.isSynthetic,
isFinal: true,
isLocalFunction: true)
isLocalFunction: true,
isWildcard:
libraryFeatures.wildcardVariables.isEnabled && name.name == '_')
..fileOffset = name.nameOffset;
// TODO(ahe): Why are we looking up in local scope, but declaring in parent
// scope?
Expand All @@ -7220,7 +7226,9 @@ class BodyBuilder extends StackListenerImpl
// The real function node is created later.
dummyFunctionNode)
..fileOffset = beginToken.charOffset);
declareVariable(variable, scope.parent!);
if (!(libraryFeatures.wildcardVariables.isEnabled && variable.isWildcard)) {
declareVariable(variable, scope.parent!);
}
}

void enterFunction() {
Expand Down
8 changes: 6 additions & 2 deletions pkg/front_end/lib/src/fasta/source/outline_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3172,13 +3172,17 @@ class OutlineBuilder extends StackListenerImpl {
Object? type = pop();
List<MetadataBuilder>? metadata =
pop(NullValues.Metadata) as List<MetadataBuilder>?;

String? fieldName = identifier is Identifier ? identifier.name : null;
push(new RecordTypeFieldBuilder(
metadata,
type is ParserRecovery
? new InvalidTypeBuilderImpl(uri, type.charOffset)
: type as TypeBuilder,
identifier is Identifier ? identifier.name : null,
identifier is Identifier ? identifier.nameOffset : -1));
fieldName,
identifier is Identifier ? identifier.nameOffset : -1,
isWildcard:
libraryFeatures.wildcardVariables.isEnabled && fieldName == '_'));
}

@override
Expand Down
11 changes: 10 additions & 1 deletion pkg/front_end/lib/src/fasta/source/source_library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,8 @@ class SourceCompilationUnitImpl implements SourceCompilationUnit {
FormalParameterBuilder formal = new FormalParameterBuilder(
kind, modifiers, type, name, _sourceLibraryBuilder, charOffset,
fileUri: fileUri,
hasImmediatelyDeclaredInitializer: initializerToken != null)
hasImmediatelyDeclaredInitializer: initializerToken != null,
isWildcard: libraryFeatures.wildcardVariables.isEnabled && name == '_')
..initializerToken = initializerToken;
return formal;
}
Expand Down Expand Up @@ -5242,6 +5243,14 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
if (isOptional &&
formal.variable!.type.isPotentiallyNonNullable &&
!formal.hasDeclaredInitializer) {
// Wildcard optional parameters can't be used so we allow having no
// initializer.
if (libraryFeatures.wildcardVariables.isEnabled &&
formal.isWildcard &&
!formal.isSuperInitializingFormal &&
!formal.isInitializingFormal) {
continue;
}
addProblem(
templateOptionalNonNullableWithoutInitializerError.withArguments(
formal.name, formal.variable!.type),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,13 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
if ((isOptionalPositional || isOptionalNamed) &&
formal.type.isPotentiallyNonNullable &&
!formal.hasDeclaredInitializer) {
// Wildcard optional parameters can't be used so we allow having no
// initializer.
if (libraryFeatures.wildcardVariables.isEnabled &&
formal.isWildcard &&
!formal.isInitializingFormal) {
continue;
}
libraryBuilder.addProblem(
templateOptionalNonNullableWithoutInitializerError.withArguments(
formal.name!, formal.type),
Expand Down
Loading

0 comments on commit f009db7

Please sign in to comment.