Content-Length: 330510 | pFad | http://github.com/microsoft/TypeScript/pull/18654/commits/f8e2cc13918c08c9697474c3cdc516fcee9596b0

7C Strict function types by ahejlsberg · Pull Request #18654 · microsoft/TypeScript · GitHub
Skip to content

Strict function types #18654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Oct 2, 2017
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
12f5dd8
Introduce --strictFunctionTypes mode
ahejlsberg Sep 18, 2017
f8ff7f7
Use dedicated marker types for variance determination
ahejlsberg Sep 18, 2017
670d711
Add quick path for computing array variance as it is already known
ahejlsberg Sep 18, 2017
a0fa69f
Handle contravariance in type inference
ahejlsberg Sep 19, 2017
b58e0fb
Add comments
ahejlsberg Sep 19, 2017
84f7afd
Handle special case of 'void' type arguments for covariant type param…
ahejlsberg Sep 19, 2017
54eadef
Accept new baselines
ahejlsberg Sep 19, 2017
44cc8c5
Use methods in dom.generated.d.ts to opt out of strict checks
ahejlsberg Sep 19, 2017
dd466ae
Update tsconfig baselines
ahejlsberg Sep 19, 2017
24698dd
Revert dom.generated.d.ts and fix duplicate declarations
ahejlsberg Sep 20, 2017
f8e2cc1
Properly flag and structurally compare marker type references
ahejlsberg Sep 21, 2017
589e1f4
Update comment
ahejlsberg Sep 21, 2017
afc8a26
Always perform structural comparison when variance check fails
ahejlsberg Sep 22, 2017
70e8f73
Add tests
ahejlsberg Sep 22, 2017
91691f6
Strict function type checking only for certain function types
ahejlsberg Sep 25, 2017
6a481e8
Update tests
ahejlsberg Sep 25, 2017
1795614
Accept new baselines
ahejlsberg Sep 26, 2017
5613be4
Only methods and constructors are bivariant in --strictFunctionTypes …
ahejlsberg Sep 28, 2017
1609196
Accept new baselines
ahejlsberg Sep 28, 2017
0756aa1
Merge branch 'master' into strictFunctionTypes
ahejlsberg Sep 28, 2017
c626d9d
Accept new baselines
ahejlsberg Sep 28, 2017
936f98d
Addressing CR feedback
ahejlsberg Sep 29, 2017
bf75a3f
Emit .d.ts file in test
ahejlsberg Oct 2, 2017
bff843a
Improve error elaboration for invariant generic types
ahejlsberg Oct 2, 2017
c2344e0
Add error elaboration test
ahejlsberg Oct 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Properly flag and structurally compare marker type references
  • Loading branch information
ahejlsberg committed Sep 21, 2017
commit f8e2cc13918c08c9697474c3cdc516fcee9596b0
24 changes: 15 additions & 9 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8948,7 +8948,7 @@ namespace ts {

if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True;

if (source.flags & TypeFlags.MarkerType && target.flags & TypeFlags.MarkerType) {
if (source.flags & TypeFlags.MarkerType && target.flags & TypeFlags.MarkerType && !(source.flags & TypeFlags.Object || target.flags & TypeFlags.Object)) {
return source === markerSubType && target === markerSuperType ? Ternary.True : Ternary.False;
}

Expand Down Expand Up @@ -9414,9 +9414,11 @@ namespace ts {
}
}
else {
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {
// We have type references to the same generic type. Obtain the variance information for the
// type parameters and relate the type arguments accordingly.
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target &&
!(source.flags & TypeFlags.MarkerType || target.flags & TypeFlags.MarkerType)) {
// We have type references to the same generic type, and the type references are not marker
// type references (which we always compare structurally). Obtain the variance information
// for the type parameters and relate the type arguments accordingly.
const variances = getVariances((<TypeReference>source).target);
if (result = typeArgumentsRelatedTo(<TypeReference>source, <TypeReference>target, variances, reportErrors)) {
return result;
Expand Down Expand Up @@ -9841,8 +9843,12 @@ namespace ts {
}
}

function getVarianceType(type: GenericType, source: TypeParameter, target: Type) {
return createTypeReference(type, map(type.typeParameters, t => t === source ? target : t));
// Return a type reference where the source type parameter is replaced with the target marker
// type, and flag the result as a marker type reference.
function getMarkerTypeReference(type: GenericType, source: TypeParameter, target: Type) {
const result = createTypeReference(type, map(type.typeParameters, t => t === source ? target : t));
result.flags |= TypeFlags.MarkerType;
return result;
}

// Return an array containing the variance of each type parameter. The variance is effectively
Expand All @@ -9867,15 +9873,15 @@ namespace ts {
// We first compare instantiations where the type parameter is replaced with
// marker types that have a known subtype relationship. From this we can infer
// invariance, covariance, contravariance or bivariance.
const typeWithSuper = getVarianceType(type, tp, markerSuperType);
const typeWithSub = getVarianceType(type, tp, markerSubType);
const typeWithSuper = getMarkerTypeReference(type, tp, markerSuperType);
const typeWithSub = getMarkerTypeReference(type, tp, markerSubType);
let variance = (isTypeAssignableTo(typeWithSub, typeWithSuper) ? Variance.Covariant : 0) |
(isTypeAssignableTo(typeWithSuper, typeWithSub) ? Variance.Contravariant : 0);
// If the instantiations appear to be related bivariantly, it may be because the
// type parameter is omnivariant (i.e. it isn't witnessed anywhere in the generic
// type). To determine this we compare instantiations where the type parameter is
// replaced with marker types that are known to be unrelated.
if (variance === Variance.Bivariant && isTypeAssignableTo(getVarianceType(type, tp, markerOtherType), typeWithSuper)) {
if (variance === Variance.Bivariant && isTypeAssignableTo(getMarkerTypeReference(type, tp, markerOtherType), typeWithSuper)) {
variance = Variance.Omnivariant;
}
variances.push(variance);
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/microsoft/TypeScript/pull/18654/commits/f8e2cc13918c08c9697474c3cdc516fcee9596b0

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy