Skip to content

Commit

Permalink
Version 3.4.0-178.0.dev
Browse files Browse the repository at this point in the history
Merge 39e240c into dev
  • Loading branch information
Dart CI committed Feb 26, 2024
2 parents 2228760 + 39e240c commit 2876f56
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scorecards-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

# Upload the results as artifacts (optional).
- name: "Upload artifact"
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3
with:
name: SARIF file
path: results.sarif
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/third-party-deps-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: "extract deps, find commit hash, pass to osv-scanner"
run: python .github/extract_deps.py --output osv-lockfile-${{github.sha}}.json
- name: "upload osv-scanner deps"
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3
with:
# use github.ref in name to avoid duplicated artifacts
name: osv-lockfile-${{github.sha}}
Expand Down
11 changes: 9 additions & 2 deletions pkg/analyzer/lib/src/dart/resolver/type_property_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/syntactic_entity.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/nullability_suffix.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/diagnostic/diagnostic.dart';
import 'package:analyzer/src/dart/element/element.dart';
Expand Down Expand Up @@ -87,8 +88,14 @@ class TypePropertyResolver {
return _toResult();
}

if (_typeSystem.isPotentiallyNullable(receiverType) &&
!receiverType.isExtensionType) {
bool isNullable;
if (receiverType.isExtensionType) {
isNullable = receiverType.nullabilitySuffix == NullabilitySuffix.question;
} else {
isNullable = _typeSystem.isPotentiallyNullable(receiverType);
}

if (isNullable) {
_lookupInterfaceType(_typeProvider.objectType);
if (_hasGetterOrSetter) {
return _toResult();
Expand Down
65 changes: 65 additions & 0 deletions pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4320,6 +4320,71 @@ MethodInvocation
''');
}

test_hasReceiver_interfaceType_extensionType_declared_nullableType() async {
await assertErrorsInCode(r'''
extension type A(int it) {
int foo() => 0;
}
void f(A? a) {
a.foo();
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
67, 3),
]);

final node = findNode.singleMethodInvocation;
assertResolvedNodeText(node, r'''
MethodInvocation
target: SimpleIdentifier
token: a
staticElement: self::@function::f::@parameter::a
staticType: A?
operator: .
methodName: SimpleIdentifier
token: foo
staticElement: self::@extensionType::A::@method::foo
staticType: int Function()
argumentList: ArgumentList
leftParenthesis: (
rightParenthesis: )
staticInvokeType: int Function()
staticType: int
''');
}

test_hasReceiver_interfaceType_extensionType_declared_nullableType_nullAware() async {
await assertNoErrorsInCode(r'''
extension type A(int it) {
int foo() => 0;
}
void f(A? a) {
a?.foo();
}
''');

final node = findNode.singleMethodInvocation;
assertResolvedNodeText(node, r'''
MethodInvocation
target: SimpleIdentifier
token: a
staticElement: self::@function::f::@parameter::a
staticType: A?
operator: ?.
methodName: SimpleIdentifier
token: foo
staticElement: self::@extensionType::A::@method::foo
staticType: int Function()
argumentList: ArgumentList
leftParenthesis: (
rightParenthesis: )
staticInvokeType: int Function()
staticType: int?
''');
}

test_hasReceiver_interfaceType_extensionType_exposed() async {
await assertNoErrorsInCode(r'''
class A {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,64 @@ PrefixedIdentifier
''');
}

test_ofExtensionType_read_nullableType() async {
await assertErrorsInCode(r'''
extension type A(int it) {
int get foo => 0;
}
void f(A? a) {
a.foo;
}
''', [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
69, 3),
]);

final node = findNode.singlePrefixedIdentifier;
assertResolvedNodeText(node, r'''
PrefixedIdentifier
prefix: SimpleIdentifier
token: a
staticElement: self::@function::f::@parameter::a
staticType: A?
period: .
identifier: SimpleIdentifier
token: foo
staticElement: self::@extensionType::A::@getter::foo
staticType: int
staticElement: self::@extensionType::A::@getter::foo
staticType: int
''');
}

test_ofExtensionType_read_nullableType_nullAware() async {
await assertNoErrorsInCode(r'''
extension type A(int it) {
int get foo => 0;
}
void f(A? a) {
a?.foo;
}
''');

final node = findNode.singlePropertyAccess;
assertResolvedNodeText(node, r'''
PropertyAccess
target: SimpleIdentifier
token: a
staticElement: self::@function::f::@parameter::a
staticType: A?
operator: ?.
propertyName: SimpleIdentifier
token: foo
staticElement: self::@extensionType::A::@getter::foo
staticType: int
staticType: int?
''');
}

test_ofExtensionType_write() async {
await assertNoErrorsInCode(r'''
extension type A(int it) {
Expand Down
9 changes: 8 additions & 1 deletion pkg/dart2wasm/lib/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import 'package:kernel/kernel.dart' show writeComponentToText;
import 'package:kernel/verifier.dart';

import 'package:vm/kernel_front_end.dart' show writeDepfile;

import 'package:vm/transformations/unreachable_code_elimination.dart'
as unreachable_code_elimination;
import 'package:vm/transformations/type_flow/transformer.dart' as globalTypeFlow
show transformComponent;
import 'package:vm/transformations/mixin_deduplication.dart'
as mixin_deduplication show transformComponent;

import 'package:dart2wasm/compiler_options.dart' as compiler;
import 'package:dart2wasm/constant_evaluator.dart';
import 'package:dart2wasm/js/runtime_generator.dart' as js;
import 'package:dart2wasm/record_class_generator.dart';
import 'package:dart2wasm/records.dart';
Expand Down Expand Up @@ -110,6 +112,11 @@ Future<CompilerOutput?> compileToModule(compiler.WasmCompilerOptions options,
CoreTypes coreTypes = compilerResult.coreTypes!;
ClassHierarchy classHierarchy = compilerResult.classHierarchy!;

ConstantEvaluator constantEvaluator =
ConstantEvaluator(options, target, component, coreTypes, classHierarchy);
unreachable_code_elimination.transformComponent(target, component,
constantEvaluator, options.translatorOptions.enableAsserts);

if (options.dumpKernelAfterCfe != null) {
writeComponentToText(component, path: options.dumpKernelAfterCfe!);
}
Expand Down
35 changes: 35 additions & 0 deletions pkg/dart2wasm/lib/constant_evaluator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2024, 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.

import 'package:kernel/ast.dart';
import 'package:kernel/type_environment.dart';
import 'package:front_end/src/fasta/kernel/constant_evaluator.dart' as kernel;
import 'package:kernel/core_types.dart';
import 'package:kernel/class_hierarchy.dart';

import 'package:vm/transformations/vm_constant_evaluator.dart';

import 'package:dart2wasm/compiler_options.dart';
import 'package:dart2wasm/target.dart';

class ConstantEvaluator extends kernel.ConstantEvaluator
implements VMConstantEvaluator {
ConstantEvaluator(WasmCompilerOptions options, WasmTarget target,
Component component, CoreTypes coreTypes, ClassHierarchy classHierarchy)
: super(
target.dartLibrarySupport,
target.constantsBackend,
component,
options.environment,
TypeEnvironment(coreTypes, classHierarchy),
const kernel.SimpleErrorReporter(),
enableTripleShift: true,
enableAsserts: options.translatorOptions.enableAsserts,
errorOnUnevaluatedConstant: true,
evaluationMode: kernel.EvaluationMode.strong,
);

@override
bool shouldEvaluateMember(Member node) => false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,15 @@ class _MacroListener implements Listener {
constructorName,
new macro.Arguments(argumentsNode.positionalArguments,
argumentsNode.namedArguments),
fileUri: uri,
fileOffset: beginToken.next!.charOffset)));
return;
}
} else {
if (_macroClassBuilder != null && _unhandledReason != null) {
_erroneousMacroApplication = new MacroApplication.error(
_unhandledReason!, _macroClassBuilder!,
fileOffset: beginToken.next!.charOffset);
fileUri: uri, fileOffset: beginToken.next!.charOffset);
}
}
pushUnsupported();
Expand Down
4 changes: 2 additions & 2 deletions pkg/front_end/lib/src/fasta/kernel/macro/identifiers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ class TypeDeclarationBuilderIdentifier extends IdentifierImpl {
return typeDeclarationBuilder.buildAliasedTypeWithBuiltArguments(
libraryBuilder,
nullabilityBuilder.build(libraryBuilder),
typeArguments,
TypeUse.macroTypeArgument,
// TODO(johnniwinther): How should handle malbounded types here? Should
// we report an error on the annotation?
typeArguments,
TypeUse.macroTypeArgument,
missingUri,
TreeNode.noOffset,
hasExplicitTypeArguments: true);
Expand Down
49 changes: 45 additions & 4 deletions pkg/front_end/lib/src/fasta/kernel/macro/introspectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class MacroIntrospection {

Map<ClassBuilder, macro.ParameterizedTypeDeclaration> _classDeclarations = {};
Map<macro.ParameterizedTypeDeclaration, ClassBuilder> _classBuilders = {};
Map<NominalVariableBuilder, macro.TypeParameterDeclarationImpl>
_typeParameters = {};
Map<TypeAliasBuilder, macro.TypeAliasDeclaration> _typeAliasDeclarations = {};
Map<MemberBuilder, macro.Declaration?> _memberDeclarations = {};
Map<LibraryBuilder, macro.LibraryImpl> _libraries = {};
Expand Down Expand Up @@ -178,8 +180,9 @@ class MacroIntrospection {
libraryBuilder: builder.libraryBuilder,
id: macro.RemoteInstance.uniqueId,
name: builder.name);
// TODO(johnniwinther): Support typeParameters
final List<macro.TypeParameterDeclarationImpl> typeParameters = [];
final List<macro.TypeParameterDeclarationImpl> typeParameters =
_nominalVariableBuildersToDeclarations(
builder.libraryBuilder, builder.typeVariables);
final List<macro.NamedTypeAnnotationImpl> interfaces =
types.typeBuildersToAnnotations(
builder.libraryBuilder, builder.interfaceBuilders);
Expand Down Expand Up @@ -229,6 +232,9 @@ class MacroIntrospection {
macro.TypeAliasDeclaration _createTypeAliasDeclaration(
TypeAliasBuilder builder) {
final macro.LibraryImpl library = getLibrary(builder.libraryBuilder);
List<macro.TypeParameterDeclarationImpl> typeParameters =
_nominalVariableBuildersToDeclarations(
builder.libraryBuilder, builder.typeVariables);
macro.TypeAliasDeclaration declaration = new macro.TypeAliasDeclarationImpl(
id: macro.RemoteInstance.uniqueId,
identifier: new TypeDeclarationBuilderIdentifier(
Expand All @@ -239,8 +245,7 @@ class MacroIntrospection {
library: library,
// TODO: Provide metadata annotations.
metadata: const [],
// TODO(johnniwinther): Support typeParameters
typeParameters: [],
typeParameters: typeParameters,
aliasedType:
types.computeTypeAnnotation(builder.libraryBuilder, builder.type));
return declaration;
Expand Down Expand Up @@ -466,6 +471,42 @@ class MacroIntrospection {
builder.libraryBuilder, builder.type));
}
}

macro.TypeParameterDeclarationImpl _createTypeParameterDeclaration(
LibraryBuilder libraryBuilder,
NominalVariableBuilder nominalVariableBuilder) {
final macro.LibraryImpl library = getLibrary(libraryBuilder);
return new macro.TypeParameterDeclarationImpl(
id: macro.RemoteInstance.uniqueId,
identifier: new TypeDeclarationBuilderIdentifier(
typeDeclarationBuilder: nominalVariableBuilder,
libraryBuilder: libraryBuilder,
id: macro.RemoteInstance.uniqueId,
name: nominalVariableBuilder.name),
library: library,
// TODO: Provide metadata annotations.
metadata: const [],
bound: types.computeTypeAnnotation(
libraryBuilder, nominalVariableBuilder.bound));
}

macro.TypeParameterDeclarationImpl _getTypeParameterDeclaration(
LibraryBuilder libraryBuilder,
NominalVariableBuilder nominalVariableBuilder) {
return _typeParameters[nominalVariableBuilder] ??=
_createTypeParameterDeclaration(libraryBuilder, nominalVariableBuilder);
}

List<macro.TypeParameterDeclarationImpl>
_nominalVariableBuildersToDeclarations(LibraryBuilder libraryBuilder,
List<NominalVariableBuilder>? typeParameterBuilders) {
return typeParameterBuilders == null
? []
: typeParameterBuilders
.map((NominalVariableBuilder typeBuilder) =>
_getTypeParameterDeclaration(libraryBuilder, typeBuilder))
.toList();
}
}

class _TypePhaseIntrospector implements macro.TypePhaseIntrospector {
Expand Down
Loading

0 comments on commit 2876f56

Please sign in to comment.