Skip to content

Commit

Permalink
More restrictive subtyping for tuple() and fun()
Browse files Browse the repository at this point in the history
Summary:
Gradual subtyping for `tuple()` and `fun()` was too lenient, leading to imprecise narrowing/meet operations.

Changing it to only allow `tuple() < {none()}` when `tuple()` is under negative polarity.

Reviewed By: ilya-klyuchnikov

Differential Revision: D51160176

fbshipit-source-id: bf6e58f5b7ac2256c3c9c0042719769dd7cea8e0
  • Loading branch information
VLanvin authored and facebook-github-bot committed Nov 9, 2023
1 parent 2510e16 commit a93581e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 5 additions & 5 deletions eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/Subtype.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,21 @@ class Subtype(pipelineContext: PipelineContext) {
subTypePol(recDecl.fields(fName).tp, fTy, seen)
}
}
case (AnyTupleType, TupleType(_)) if pipelineContext.gradualTyping =>
case (AnyTupleType, TupleType(_)) if pipelineContext.gradualTyping && v1 == - =>
true
case (AnyTupleType, RecordType(_)) if pipelineContext.gradualTyping =>
case (AnyTupleType, RecordType(_)) if pipelineContext.gradualTyping && v1 == - =>
true
case (AnyTupleType, RefinedRecordType(_, _)) if pipelineContext.gradualTyping =>
case (AnyTupleType, RefinedRecordType(_, _)) if pipelineContext.gradualTyping && v1 == - =>
true
case (FunType(_, _, _), AnyFunType) if pipelineContext.gradualTyping =>
true
case (AnyFunType, FunType(_, _, _)) if pipelineContext.gradualTyping =>
case (AnyFunType, FunType(_, _, _)) if pipelineContext.gradualTyping && v1 == - =>
true
case (FunType(_, argTys, _), AnyFunType) =>
argTys.forall(subTypePol(AnyType, _, seen))
case (AnyArityFunType(_), AnyFunType) =>
true
case (AnyFunType, AnyArityFunType(_)) if pipelineContext.gradualTyping =>
case (AnyFunType, AnyArityFunType(_)) if pipelineContext.gradualTyping && v1 == - =>
true
case (FunType(_, _, resTy1), AnyArityFunType(resTy2)) =>
subTypePol(resTy1, resTy2, seen)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,12 @@ fuzz03([_ | {}]) -> | OK |
| |
-spec refine_tuple_neg(a | {b, c}) | |
-> a | {none()}. | |
refine_tuple_neg(T) when is_tuple(T) -> T; | OK |
refine_tuple_neg(T) when is_tuple(T) -> T; | ERROR | T.
| | Expression has type: none() | {'b', 'c'}
| | Context expected type: 'a' | {none()}
| |
| | none() | {'b', 'c'} is not compatible with 'a' | {none()}
| | because
| | {'b', 'c'} is not compatible with 'a' | {none()}
| | expected union does not contain any tuple type of size 2
refine_tuple_neg(T) -> T. | |

0 comments on commit a93581e

Please sign in to comment.