Skip to content

Commit

Permalink
Version 3.8.0-55.0.dev
Browse files Browse the repository at this point in the history
Merge bfc2fc0 into dev
  • Loading branch information
Dart CI committed Jan 30, 2025
2 parents 2c3b07e + bfc2fc0 commit 25f17fd
Show file tree
Hide file tree
Showing 13 changed files with 897 additions and 718 deletions.
30 changes: 25 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@

- Added `Iterable.withIterator` constructor.

### Tools

#### Dart Development Compiler (dartdevc)

In order to align with dart2js semantics, DDC will now throw a runtime error
when a redirecting factory is torn off and one of its optional non-nullable
parameters is provided no value. The implicit null passed to the factory will
not match the non-nullable type and this will now throw.

In the future this will likely be a compile-time error and will be entirely
disallowed.

## 3.7.0

**Released on:** Unreleased
Expand Down Expand Up @@ -304,12 +316,24 @@ AOT snapshot can be used as follows to run DDC <dart-sdk>/bin/dartaotruntime

## 3.6.2

**Released on:** Unreleased
**Released on:** 2025-01-30

- Fixes a bug where `HttpServer` responses were not correctly encoded
if a "Content-Type" header was set (issue [#59719][]).
- Fix `dart format` to parse code at language version 3.6 so that digit
separators can be parsed correctly (issue [#59815][], dart_style issue
[#1630][dart_style #1630]).
- Fixes an issue where the DevTools analytics did not distinguish
between new and legacy inspector events (issue [#59884][]).
- When running `dart fix` on a folder that contains a library with multiple
files and more than one needs a fix, the fix will now be applied correctly
only once to each file (issue [#59572][]).

[#59719]: https://github.com/dart-lang/sdk/issues/59719
[#59815]: https://github.com/dart-lang/sdk/issues/59815
[dart_style #1630]: https://github.com/dart-lang/dart_style/issues/1630
[#59884]: https://github.com/dart-lang/sdk/issues/59884
[#59572]: https://github.com/dart-lang/sdk/issues/59572

## 3.6.1

Expand All @@ -324,14 +348,10 @@ AOT snapshot can be used as follows to run DDC <dart-sdk>/bin/dartaotruntime
[#57084][]).
- Fixes analysis options discovery in the presence of workspaces
(issue [#56552][]).
- When running `dart fix` on a folder that contains a library with multiple
files and more than one needs a fix, the fix will now be applied correctly
only once to each file (issue [#59572][]).

[pub#4445]: https://github.com/dart-lang/pub/issues/4445
[#57084]: https://github.com/dart-lang/sdk/issues/57084
[#56552]: https://github.com/dart-lang/sdk/issues/56552
[#59572]: https://github.com/dart-lang/sdk/issues/59572

## 3.6.0

Expand Down
23 changes: 19 additions & 4 deletions pkg/dev_compiler/lib/src/kernel/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3857,7 +3857,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>

_emitCovarianceBoundsCheck(f.typeParameters, body);

void initParameter(VariableDeclaration p, js_ast.Identifier jsParam) {
void initParameter(
VariableDeclaration p, js_ast.Identifier jsParam, bool isOptional) {
// When the parameter is covariant, insert the null check before the
// covariant cast to avoid a TypeError when testing equality with null.
if (name == '==') {
Expand All @@ -3870,7 +3871,19 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
// Eliminate it when possible.
body.add(js.statement('if (# == null) return false;', [jsParam]));
}
if (isCovariantParameter(p)) {
if (isCovariantParameter(p) ||
// TODO(52582): This should be unreachable once the CFE ensures that
// redirecting factories parameter types match the target constructor.
// Matches dart2js check semantics for redirecting factory tearoffs.
// If a non-nullable optional argument with a null initializer is
// detected, we add an additional covariant check at runtime.
(f.parent is Procedure &&
isOptional &&
isConstructorTearOffLowering(f.parent as Procedure) &&
!p.type.isPotentiallyNullable &&
!p.initializer!
.getStaticType(_staticTypeContext)
.isPotentiallyNonNullable)) {
var castExpr = _emitCast(jsParam, p.type);
if (!identical(castExpr, jsParam)) body.add(castExpr.toStatement());
}
Expand All @@ -3884,11 +3897,13 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
}
}

var counter = 0;
for (var p in f.positionalParameters) {
var jsParam = _emitVariableRef(p);
if (_checkParameters) {
initParameter(p, jsParam);
initParameter(p, jsParam, counter >= f.requiredParameterCount);
}
counter++;
}
for (var p in f.namedParameters) {
// Parameters will be passed using their real names, not the (possibly
Expand All @@ -3906,7 +3921,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
]));

if (_checkParameters) {
initParameter(p, jsParam);
initParameter(p, jsParam, !p.isRequired);
}
}

Expand Down
23 changes: 19 additions & 4 deletions pkg/dev_compiler/lib/src/kernel/compiler_new.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4256,7 +4256,8 @@ class LibraryCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>

_emitCovarianceBoundsCheck(f.typeParameters, body);

void initParameter(VariableDeclaration p, js_ast.Identifier jsParam) {
void initParameter(
VariableDeclaration p, js_ast.Identifier jsParam, bool isOptional) {
// When the parameter is covariant, insert the null check before the
// covariant cast to avoid a TypeError when testing equality with null.
if (name == '==') {
Expand All @@ -4269,7 +4270,19 @@ class LibraryCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
// Eliminate it when possible.
body.add(js.statement('if (# == null) return false;', [jsParam]));
}
if (isCovariantParameter(p)) {
if (isCovariantParameter(p) ||
// TODO(52582): This should be unreachable once the CFE ensures that
// redirecting factories parameter types match the target constructor.
// Matches dart2js check semantics for redirecting factory tearoffs.
// If a non-nullable optional argument with a null initializer is
// detected, we add an additional covariant check at runtime.
(f.parent is Procedure &&
isOptional &&
isConstructorTearOffLowering(f.parent as Procedure) &&
!p.type.isPotentiallyNullable &&
!p.initializer!
.getStaticType(_staticTypeContext)
.isPotentiallyNonNullable)) {
var castExpr = _emitCast(jsParam, p.type);
if (!identical(castExpr, jsParam)) body.add(castExpr.toStatement());
}
Expand All @@ -4283,11 +4296,13 @@ class LibraryCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
}
}

var counter = 0;
for (var p in f.positionalParameters) {
var jsParam = _emitVariableRef(p);
if (_checkParameters) {
initParameter(p, jsParam);
initParameter(p, jsParam, counter >= f.requiredParameterCount);
}
counter++;
}
for (var p in f.namedParameters) {
// Parameters will be passed using their real names, not the (possibly
Expand All @@ -4305,7 +4320,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
]));

if (_checkParameters) {
initParameter(p, jsParam);
initParameter(p, jsParam, !p.isRequired);
}
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/front_end/lib/src/fragment/factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,17 @@ class _FactoryBodyBuildingContext implements FunctionBodyBuildingContext {

@override
LocalScope computeFormalParameterScope(LookupScope typeParameterScope) {
return _fragment.builder.computeFormalParameterScope(typeParameterScope);
if (_fragment.formals == null) {
return new FormalParameterScope(parent: typeParameterScope);
}
Map<String, Builder> local = <String, Builder>{};
for (FormalParameterBuilder formal in _fragment.formals!) {
if (formal.isWildcard) {
continue;
}
local[formal.name] = formal;
}
return new FormalParameterScope(local: local, parent: typeParameterScope);
}

@override
Expand Down
75 changes: 10 additions & 65 deletions pkg/front_end/lib/src/kernel/body_builder_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import '../source/source_constructor_builder.dart';
import '../source/source_enum_builder.dart';
import '../source/source_extension_builder.dart';
import '../source/source_extension_type_declaration_builder.dart';
import '../source/source_factory_builder.dart';
import '../source/source_function_builder.dart';
import '../source/source_library_builder.dart';
import '../source/source_member_builder.dart';
Expand Down Expand Up @@ -759,11 +758,6 @@ mixin _FunctionBodyBuilderContextMixin<T extends SourceFunctionBuilder>
@override
List<FormalParameterBuilder>? get formals => _member.formals;

@override
LocalScope computeFormalParameterInitializerScope(LocalScope parent) {
return _member.computeFormalParameterInitializerScope(parent);
}

@override
FormalParameterBuilder? getFormalParameterByName(Identifier name) {
return _member.getFormal(name);
Expand Down Expand Up @@ -872,6 +866,11 @@ class ConstructorBodyBuilderContext extends BodyBuilderContext
: super(_member.libraryBuilder, _member.declarationBuilder,
isDeclarationInstanceMember: _member.isDeclarationInstanceMember);

@override
LocalScope computeFormalParameterInitializerScope(LocalScope parent) {
return _member.computeFormalParameterInitializerScope(parent);
}

@override
void setBody(Statement body) {
_member.body = body;
Expand Down Expand Up @@ -907,6 +906,11 @@ class ExtensionTypeConstructorBodyBuilderContext extends BodyBuilderContext
: super(_member.libraryBuilder, _member.declarationBuilder,
isDeclarationInstanceMember: _member.isDeclarationInstanceMember);

@override
LocalScope computeFormalParameterInitializerScope(LocalScope parent) {
return _member.computeFormalParameterInitializerScope(parent);
}

@override
void setBody(Statement body) {
_member.body = body;
Expand All @@ -921,65 +925,6 @@ class ExtensionTypeConstructorBodyBuilderContext extends BodyBuilderContext
TreeNode get _initializerParent => _member.invokeTarget;
}

class FactoryBodyBuilderContext extends BodyBuilderContext
with
_MemberBodyBuilderContext<SourceFactoryBuilder>,
_FunctionBodyBuilderContextMixin<SourceFactoryBuilder> {
@override
final SourceFactoryBuilder _member;

@override
final Member _builtMember;

FactoryBodyBuilderContext(this._member, this._builtMember)
: super(_member.libraryBuilder, _member.declarationBuilder,
isDeclarationInstanceMember: _member.isDeclarationInstanceMember);

@override
void setBody(Statement body) {
_member.setBody(body);
}

@override
void setAsyncModifier(AsyncMarker asyncModifier) {
_member.asyncModifier = asyncModifier;
}

@override
DartType get returnTypeContext {
return _member.function.returnType;
}
}

class RedirectingFactoryBodyBuilderContext extends BodyBuilderContext
with
_MemberBodyBuilderContext<SourceFactoryBuilder>,
_FunctionBodyBuilderContextMixin<SourceFactoryBuilder> {
@override
final SourceFactoryBuilder _member;

@override
final Member _builtMember;

RedirectingFactoryBodyBuilderContext(this._member, this._builtMember)
: super(_member.libraryBuilder, _member.declarationBuilder,
isDeclarationInstanceMember: _member.isDeclarationInstanceMember);

@override
// Coverage-ignore(suite): Not run.
void setBody(Statement body) {
_member.setBody(body);
}

@override
bool get isRedirectingFactory => true;

@override
String get redirectingFactoryTargetName {
return _member.redirectionTarget!.fullNameForErrors;
}
}

class ParameterBodyBuilderContext extends BodyBuilderContext {
factory ParameterBodyBuilderContext(
LibraryBuilder libraryBuilder,
Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/source/class_declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ mixin ClassDeclarationMixin implements ClassDeclaration {
fileOffset, fileUri);
}
if (declaration is SourceFactoryBuilder) {
declaration.resolveRedirectingFactory(this);
declaration.resolveRedirectingFactory();
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/front_end/lib/src/source/source_constructor_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ abstract class AbstractSourceConstructorBuilder extends SourceMemberBuilderImpl
/// of a augmented member or by not being the last among augmentations.
bool get isAugmented;

@override
LocalScope computeFormalParameterScope(LookupScope parent) {
if (formals == null) return new FormalParameterScope(parent: parent);
Map<String, Builder> local = <String, Builder>{};
Expand All @@ -191,7 +190,6 @@ abstract class AbstractSourceConstructorBuilder extends SourceMemberBuilderImpl
return new FormalParameterScope(local: local, parent: parent);
}

@override
LocalScope computeFormalParameterInitializerScope(LocalScope parent) {
// From
// [dartLangSpec.tex](../../../../../../docs/language/dartLangSpec.tex) at
Expand Down
Loading

0 comments on commit 25f17fd

Please sign in to comment.