Infer function expressions in matching contexts (#514)

* legalizes omitting types on function expressions within function type contexts
* legalizes omitting any number of arguments
This commit is contained in:
Daniel Wirtz
2019-02-27 21:45:36 +01:00
committed by GitHub
parent 2945af6557
commit e8b0767143
29 changed files with 1349 additions and 701 deletions

View File

@ -197,7 +197,7 @@ export class Type {
return this.cachedNullableType;
}
/** Tests if a value of this type is assignable to a target of the specified type. */
/** Tests if a value of this type is assignable to the target type incl. implicit conversion. */
isAssignableTo(target: Type, signednessIsRelevant: bool = false): bool {
var currentClass: Class | null;
var targetClass: Class | null;
@ -245,8 +245,20 @@ export class Type {
return false;
}
/** Determines the common compatible type of two types, if any. */
static commonCompatible(left: Type, right: Type, signednessIsImportant: bool): Type | null {
/** Tests if a value of this type is assignable to the target type excl. implicit conversion. */
isStrictlyAssignableTo(target: Type, signednessIsRelevant: bool = false): bool {
if (this.is(TypeFlags.REFERENCE)) return this.isAssignableTo(target);
else if (target.is(TypeFlags.REFERENCE)) return false;
if (this.is(TypeFlags.INTEGER)) {
return target.is(TypeFlags.INTEGER) && target.size == this.size && (
!signednessIsRelevant || this.is(TypeFlags.SIGNED) == target.is(TypeFlags.SIGNED)
);
}
return this.kind == target.kind;
}
/** Determines the common denominator type of two types, if there is any. */
static commonDenominator(left: Type, right: Type, signednessIsImportant: bool): Type | null {
if (right.isAssignableTo(left, signednessIsImportant)) return left;
else if (left.isAssignableTo(right, signednessIsImportant)) return right;
return null;