Skip to content

Commit

Permalink
more precise narrow.getValType
Browse files Browse the repository at this point in the history
Summary:
- narrow.getValType is used for elaborating `maps:get/2` and `maps:get/3`
- returning NoneType if we can safely deduce it. See the tests

Reviewed By: michalmuskala

Differential Revision: D66961955

fbshipit-source-id: 0a0488b8e486fb32a8d719512a0f010b158ca562
  • Loading branch information
ilya-klyuchnikov authored and facebook-github-bot committed Dec 9, 2024
1 parent 5451996 commit 626451b
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,14 @@ class Narrow(pipelineContext: PipelineContext) {
subtype.join(t.vType, t.props.values.map(_.tp))

def getValType(key: Key, t: MapType): Type =
t.props.get(key).map(_.tp).getOrElse(t.vType)
t.props.get(key).map(_.tp).getOrElse {
// key represents a literal type
// so we can use subtyping for testing non-empty intersection
if (subtype.subType(Key.asType(key), t.kType))
t.vType
else
NoneType
}

def withRequiredProp(k: Key, t: MapType): Option[MapType] =
t.props.get(k) match {
Expand Down

0 comments on commit 626451b

Please sign in to comment.