Skip to content

Commit

Permalink
Version 2.13.0-103.0.dev
Browse files Browse the repository at this point in the history
Merge commit 'e9f4d5dbb1ea95e7fac59189dc36474953d58e4a' into 'dev'
  • Loading branch information
Dart CI committed Mar 4, 2021
2 parents 96183ee + e9f4d5d commit 8d3ed9f
Show file tree
Hide file tree
Showing 45 changed files with 1,377 additions and 97 deletions.
25 changes: 13 additions & 12 deletions pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart
Expand Up @@ -811,7 +811,7 @@ class ConstantsTransformer extends RemovingTransformer {
}
}

class ConstantEvaluator extends RecursiveResultVisitor<Constant> {
class ConstantEvaluator extends ExpressionVisitor<Constant> {
final ConstantsBackend backend;
final NumberSemantics numberSemantics;
ConstantIntFolder intFolder;
Expand Down Expand Up @@ -1157,7 +1157,7 @@ class ConstantEvaluator extends RecursiveResultVisitor<Constant> {
}

@override
Constant defaultTreeNode(Node node) {
Constant defaultExpression(Expression node) {
// Only a subset of the expression language is valid for constant
// evaluation.
return createInvalidExpressionConstant(
Expand Down Expand Up @@ -2738,19 +2738,20 @@ class ConstantEvaluator extends RecursiveResultVisitor<Constant> {
if (value is AbortConstant) return value;
env.addVariableValue(parameter, value);
}
return function.body.accept(this);
Statement body = function.body;
if (body is ReturnStatement) {
if (!enableConstFunctions) {
return createInvalidExpressionConstant(
node, "Return statements are not supported.");
}
return body.expression.accept(this);
} else {
return createInvalidExpressionConstant(
node, "Unsupported statement: ${body.runtimeType}.");
}
});
}

@override
Constant visitReturnStatement(ReturnStatement node) {
if (!enableConstFunctions) {
return createInvalidExpressionConstant(
node, "Return statements are not supported.");
}
return node.expression.accept(this);
}

@override
Constant visitAsExpression(AsExpression node) {
final Constant constant = _evaluateSubexpression(node.operand);
Expand Down
8 changes: 5 additions & 3 deletions pkg/front_end/lib/src/fasta/source/source_class_builder.dart
Expand Up @@ -425,19 +425,21 @@ class SourceClassBuilder extends ClassBuilderImpl
Library library = libraryBuilder.library;

List<TypeArgumentIssue> issues = findTypeArgumentIssues(
library,
new InterfaceType(
supertype.classNode, library.nonNullable, supertype.typeArguments),
typeEnvironment,
libraryBuilder.isNonNullableByDefault
? SubtypeCheckMode.withNullabilities
: SubtypeCheckMode.ignoringNullabilities,
allowSuperBounded: false);
allowSuperBounded: false,
isNonNullableByDefault: library.isNonNullableByDefault,
areGenericArgumentsAllowed:
libraryBuilder.enableGenericMetadataInLibrary);
for (TypeArgumentIssue issue in issues) {
DartType argument = issue.argument;
TypeParameter typeParameter = issue.typeParameter;
bool inferred = libraryBuilder.inferredTypes.contains(argument);
if (isGenericFunctionTypeOrAlias(argument)) {
if (issue.isGenericTypeAsArgumentIssue) {
if (inferred) {
// Supertype can't be or contain super-bounded types, so null is
// passed for super-bounded hint here.
Expand Down
62 changes: 36 additions & 26 deletions pkg/front_end/lib/src/fasta/source/source_library_builder.dart
Expand Up @@ -32,8 +32,7 @@ import 'package:kernel/src/bounds_checks.dart'
TypeArgumentIssue,
findTypeArgumentIssues,
findTypeArgumentIssuesForInvocation,
getGenericTypeName,
isGenericFunctionTypeOrAlias;
getGenericTypeName;

import 'package:kernel/type_algebra.dart' show Substitution, substitute;

Expand Down Expand Up @@ -2923,15 +2922,17 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {

bool haveErroneousBounds = false;
if (!inErrorRecovery) {
for (int i = 0; i < variables.length; ++i) {
TypeVariableBuilder variable = variables[i];
List<TypeBuilder> genericFunctionTypes = <TypeBuilder>[];
findGenericFunctionTypes(variable.bound,
result: genericFunctionTypes);
if (genericFunctionTypes.length > 0) {
haveErroneousBounds = true;
addProblem(messageGenericFunctionTypeInBound, variable.charOffset,
variable.name.length, variable.fileUri);
if (!enableGenericMetadataInLibrary) {
for (int i = 0; i < variables.length; ++i) {
TypeVariableBuilder variable = variables[i];
List<TypeBuilder> genericFunctionTypes = <TypeBuilder>[];
findGenericFunctionTypes(variable.bound,
result: genericFunctionTypes);
if (genericFunctionTypes.length > 0) {
haveErroneousBounds = true;
addProblem(messageGenericFunctionTypeInBound, variable.charOffset,
variable.name.length, variable.fileUri);
}
}
}

Expand Down Expand Up @@ -3170,7 +3171,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
inferredTypes.contains(argument);
offset =
typeArgumentsInfo?.getOffsetForIndex(issue.index, offset) ?? offset;
if (isGenericFunctionTypeOrAlias(argument)) {
if (issue.isGenericTypeAsArgumentIssue) {
if (issueInferred) {
message = templateGenericFunctionTypeInferredAsActualTypeArgument
.withArguments(argument, isNonNullableByDefault);
Expand Down Expand Up @@ -3221,10 +3222,14 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
}
}

// Don't show the hint about an attempted super-bounded type if the issue
// with the argument is that it's generic.
reportTypeArgumentIssue(message, fileUri, offset,
typeParameter: typeParameter,
superBoundedAttempt: issue.enclosingType,
superBoundedAttemptInverted: issue.invertedType);
superBoundedAttempt:
issue.isGenericTypeAsArgumentIssue ? null : issue.enclosingType,
superBoundedAttemptInverted:
issue.isGenericTypeAsArgumentIssue ? null : issue.invertedType);
}
}

Expand Down Expand Up @@ -3306,13 +3311,14 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
// Check in bounds of own type variables.
for (TypeParameter parameter in typeParameters) {
List<TypeArgumentIssue> issues = findTypeArgumentIssues(
library,
parameter.bound,
typeEnvironment,
isNonNullableByDefault
? SubtypeCheckMode.withNullabilities
: SubtypeCheckMode.ignoringNullabilities,
allowSuperBounded: true);
allowSuperBounded: true,
isNonNullableByDefault: library.isNonNullableByDefault,
areGenericArgumentsAllowed: enableGenericMetadataInLibrary);
for (TypeArgumentIssue issue in issues) {
DartType argument = issue.argument;
TypeParameter typeParameter = issue.typeParameter;
Expand All @@ -3325,7 +3331,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
continue;
}

if (isGenericFunctionTypeOrAlias(argument)) {
if (issue.isGenericTypeAsArgumentIssue) {
reportTypeArgumentIssue(
messageGenericFunctionTypeUsedAsActualTypeArgument,
fileUri,
Expand Down Expand Up @@ -3382,21 +3388,22 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
}
if (!skipReturnType && returnType != null) {
List<TypeArgumentIssue> issues = findTypeArgumentIssues(
library,
returnType,
typeEnvironment,
isNonNullableByDefault
? SubtypeCheckMode.withNullabilities
: SubtypeCheckMode.ignoringNullabilities,
allowSuperBounded: true);
allowSuperBounded: true,
isNonNullableByDefault: library.isNonNullableByDefault,
areGenericArgumentsAllowed: enableGenericMetadataInLibrary);
for (TypeArgumentIssue issue in issues) {
DartType argument = issue.argument;
TypeParameter typeParameter = issue.typeParameter;

// We don't need to check if [argument] was inferred or specified
// here, because inference in return types boils down to instantiate-
// -to-bound, and it can't provide a type that violates the bound.
if (isGenericFunctionTypeOrAlias(argument)) {
if (issue.isGenericTypeAsArgumentIssue) {
reportTypeArgumentIssue(
messageGenericFunctionTypeUsedAsActualTypeArgument,
fileUri,
Expand Down Expand Up @@ -3490,13 +3497,14 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
DartType type, TypeEnvironment typeEnvironment, Uri fileUri, int offset,
{bool inferred, bool allowSuperBounded = true}) {
List<TypeArgumentIssue> issues = findTypeArgumentIssues(
library,
type,
typeEnvironment,
isNonNullableByDefault
? SubtypeCheckMode.withNullabilities
: SubtypeCheckMode.ignoringNullabilities,
allowSuperBounded: allowSuperBounded);
allowSuperBounded: allowSuperBounded,
isNonNullableByDefault: library.isNonNullableByDefault,
areGenericArgumentsAllowed: enableGenericMetadataInLibrary);
reportTypeArgumentIssues(issues, fileUri, offset, inferred: inferred);
}

Expand Down Expand Up @@ -3554,14 +3562,15 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
? const NeverType.nonNullable()
: const NullType();
List<TypeArgumentIssue> issues = findTypeArgumentIssuesForInvocation(
library,
parameters,
arguments,
typeEnvironment,
isNonNullableByDefault
? SubtypeCheckMode.withNullabilities
: SubtypeCheckMode.ignoringNullabilities,
bottomType);
bottomType,
isNonNullableByDefault: library.isNonNullableByDefault,
areGenericArgumentsAllowed: enableGenericMetadataInLibrary);
if (issues.isNotEmpty) {
DartType targetReceiver;
if (klass != null) {
Expand Down Expand Up @@ -3631,14 +3640,15 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
? const NeverType.nonNullable()
: const NullType();
List<TypeArgumentIssue> issues = findTypeArgumentIssuesForInvocation(
library,
instantiatedMethodParameters,
arguments.types,
typeEnvironment,
isNonNullableByDefault
? SubtypeCheckMode.withNullabilities
: SubtypeCheckMode.ignoringNullabilities,
bottomType);
bottomType,
isNonNullableByDefault: library.isNonNullableByDefault,
areGenericArgumentsAllowed: enableGenericMetadataInLibrary);
reportTypeArgumentIssues(issues, fileUri, offset,
typeArgumentsInfo: getTypeArgumentsInfo(arguments),
targetReceiver: receiverType,
Expand Down
11 changes: 10 additions & 1 deletion pkg/front_end/test/unit_test_suites.dart
Expand Up @@ -8,4 +8,13 @@
// By marking this file (the entry) as non-nnbd, it becomes weak mode which
// is required because many of the imports are not (yet) nnbd.

export 'unit_test_suites_impl.dart';
import 'unit_test_suites_impl.dart' as impl;

/// Work around https://github.com/dart-lang/sdk/issues/45192.
///
/// TODO(paulberry): once #45192 is fixed, we can switch the `import` directive
/// above to an `export` and remove this method, and this file will still be
/// considered by the analysis server to be runnable.
main(List<String> args) {
impl.main(args);
}
@@ -0,0 +1,48 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/general/bug21938.dart:8:4: Error: The method 'call' isn't defined for the class 'Object'.
// - 'Object' is from 'dart:core'.
// Try correcting the name to the name of an existing method, or defining a method named 'call'.
// x();
// ^
//
// pkg/front_end/testcases/general/bug21938.dart:9:4: Error: The method 'call' isn't defined for the class 'Object'.
// - 'Object' is from 'dart:core'.
// Try correcting the name to the name of an existing method, or defining a method named 'call'.
// x(3);
// ^
//
// pkg/front_end/testcases/general/bug21938.dart:11:5: Error: The method 'call' isn't defined for the class 'Object'.
// - 'Object' is from 'dart:core'.
// Try correcting the name to the name of an existing method, or defining a method named 'call'.
// x.call();
// ^^^^
//
import self as self;
import "dart:core" as core;

static method test() → dynamic {
core::Object* x;
core::Function* f;
invalid-expression "pkg/front_end/testcases/general/bug21938.dart:8:4: Error: The method 'call' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing method, or defining a method named 'call'.
x();
^";
invalid-expression "pkg/front_end/testcases/general/bug21938.dart:9:4: Error: The method 'call' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing method, or defining a method named 'call'.
x(3);
^";
f.call(5, 2);
invalid-expression "pkg/front_end/testcases/general/bug21938.dart:11:5: Error: The method 'call' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing method, or defining a method named 'call'.
x.call();
^^^^";
f.call;
f.call(5, 2);
}
static method main() → dynamic {}
@@ -0,0 +1,72 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/general/callable_type_variable.dart:25:19: Error: Too few positional arguments: 1 required, 0 given.
// var v1 = field(); // error
// ^
//
// pkg/front_end/testcases/general/callable_type_variable.dart:28:24: Error: Too few positional arguments: 1 required, 0 given.
// var v4 = field.call(); // error
// ^
//
import self as self;
import "dart:core" as core;

class Class1<T extends core::Function* = core::Function*> extends core::Object {
generic-covariant-impl field self::Class1::T* field;
constructor •(self::Class1::T* field) → self::Class1<self::Class1::T*>*
: self::Class1::field = field, super core::Object::•()
;
method method() → dynamic {
dynamic v1 = this.{self::Class1::field}.call();
dynamic v2 = let final core::int* #t1 = 0 in this.{self::Class1::field}.call(#t1);
self::Class1::T* v3 = this.{self::Class1::field}.call;
dynamic v4 = this.{self::Class1::field}.call();
dynamic v5 = this.{self::Class1::field}.call(0);
}
abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode
abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf
abstract member-signature method _simpleInstanceOfTrue(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfTrue
abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode
abstract member-signature method toString() → core::String*; -> core::Object::toString
abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod
abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
}
class Class2<T extends (core::int*) →* core::String* = (core::int*) →* core::String*> extends core::Object {
generic-covariant-impl field self::Class2::T* field;
constructor •(self::Class2::T* field) → self::Class2<self::Class2::T*>*
: self::Class2::field = field, super core::Object::•()
;
method method() → dynamic {
invalid-type v1 = let final Never* #t2 = invalid-expression "pkg/front_end/testcases/general/callable_type_variable.dart:25:19: Error: Too few positional arguments: 1 required, 0 given.
var v1 = field(); // error
^" in this.{self::Class2::field}.call();
core::String* v2 = let final core::int* #t3 = 0 in this.{self::Class2::field}.call(#t3);
self::Class2::T* v3 = this.{self::Class2::field}.call;
invalid-type v4 = let final Never* #t4 = invalid-expression "pkg/front_end/testcases/general/callable_type_variable.dart:28:24: Error: Too few positional arguments: 1 required, 0 given.
var v4 = field.call(); // error
^" in this.{self::Class2::field}.call();
core::String* v5 = this.{self::Class2::field}.call(0);
}
abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode
abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf
abstract member-signature method _simpleInstanceOfTrue(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfTrue
abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode
abstract member-signature method toString() → core::String*; -> core::Object::toString
abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod
abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
}
static method main() → dynamic {}


Extra constant evaluation status:
Evaluated: VariableGet @ org-dartlang-testcase:///callable_type_variable.dart:12:20 -> IntConstant(0)
Evaluated: VariableGet @ org-dartlang-testcase:///callable_type_variable.dart:26:20 -> IntConstant(0)
Extra constant evaluation: evaluated: 38, effectively constant: 2
@@ -0,0 +1,15 @@
// Copyright (c) 2021, 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.

class A<X> {}

A<Y> foo<Y>(Y y) => throw 42;

test() {
var x = foo(<Z>(Z) => throw 42);
var y = [foo];
var z = {y.first};
}

main() {}

0 comments on commit 8d3ed9f

Please sign in to comment.