Fix crash with generalized function types in type tests.

R=johnniwinther@google.com

Review-Url: https://codereview.chromium.org/2899693003 .
This commit is contained in:
Peter von der Ahé 2017-05-22 14:53:45 +02:00
parent cad93bb844
commit de7edcde74
6 changed files with 70 additions and 4 deletions

View file

@ -1477,6 +1477,7 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
@override
void handleFunctionType(Token functionToken, Token endToken) {
debugEvent("FunctionType");
FormalParameters formals = pop();
ignore(Unhandled.TypeVariables);
DartType returnType = pop();
@ -1590,9 +1591,9 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
}
}
variable ??= astFactory.variableDeclaration(
name.name, name.token, functionNestingLevel,
name?.name, name?.token, functionNestingLevel,
type: type,
initializer: name.initializer,
initializer: name?.initializer,
isFinal: isFinal,
isConst: isConst);
push(variable);
@ -1657,7 +1658,8 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
optional,
beginToken.charOffset);
push(formals);
if (inCatchClause || functionNestingLevel != 0) {
if ((inCatchClause || functionNestingLevel != 0) &&
kind != MemberKind.GeneralizedFunctionType) {
enterLocalScope(formals.computeFormalParameterScope(
scope, member ?? classBuilder ?? library));
}

View file

@ -0,0 +1,19 @@
// Copyright (c) 2017, 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:expect/expect.dart" show Expect;
test(f) {
if (f is void Function(Object, StackTrace)) return 1;
if (f is void Function(Object)) return 10;
if (f is void Function()) return 100;
}
main() {
Expect.equals(
111,
test(() => null) +
test((Object o) => null) +
test((Object o, StackTrace t) => null));
}

View file

@ -0,0 +1,16 @@
library;
import self as self;
import "dart:core" as core;
import "package:expect/expect.dart" as exp;
static method test(dynamic f) → dynamic {
if(f is (core::Object, core::StackTrace) → void)
return 1;
if(f is (core::Object) → void)
return 10;
if(f is () → void)
return 100;
}
static method main() → dynamic {
exp::Expect::equals(111, self::test(() → dynamic => null).+(self::test((core::Object o) → dynamic => null)).+(self::test((core::Object o, core::StackTrace t) → dynamic => null)));
}

View file

@ -0,0 +1,7 @@
library;
import self as self;
static method test(dynamic f) → dynamic
;
static method main() → dynamic
;

View file

@ -0,0 +1,16 @@
library;
import self as self;
import "dart:core" as core;
import "package:expect/expect.dart" as exp;
static method test(dynamic f) → dynamic {
if(f is (core::Object, core::StackTrace) → void)
return 1;
if(f is (core::Object) → void)
return 10;
if(f is () → void)
return 100;
}
static method main() → dynamic {
exp::Expect::equals(111, self::test(() → dynamic => null).+(self::test((core::Object o) → dynamic => null)).+(self::test((core::Object o, core::StackTrace t) → dynamic => null)));
}

View file

@ -20,6 +20,8 @@ function stop {
exit 1
}
DART_CONFIGURATION=${DART_CONFIGURATION:-ReleaseX64}
case "${1//_/-}" in
abcompile) SCRIPT="${TOOL_DIR}/abcompile.dart";;
analyzer-compile) SCRIPT="${TOOL_DIR}/analyzer_compile.dart";;
@ -49,7 +51,11 @@ case "${1//_/-}" in
;;
kernel-service)
shift
PATCHED_SDK_DIR=$(
ls -d {xcodebuild,out}/${DART_CONFIGURATION}/patched_sdk 2>/dev/null \
| head -1)
exec "${DART_VM}" -c -DDFE_VERBOSE=true \
--platform=${PATCHED_SDK_DIR}/platform.dill \
--dfe="${REPO_DIR}/utils/kernel-service/kernel-service.dart" "$@"
;;
testing)
@ -64,4 +70,4 @@ esac
shift
DART_CONFIGURATION=${DART_CONFIGURATION:-ReleaseX64} exec "${DART_VM}" -c "${SCRIPT}" "$@"
exec "${DART_VM}" -c "${SCRIPT}" "$@"