Skip to content

Commit 626451b

Browse files
ilya-klyuchnikovfacebook-github-bot
authored andcommittedDec 9, 2024·
more precise narrow.getValType
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
1 parent 5451996 commit 626451b

File tree

1 file changed

+8
-1
lines changed
  • eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc

1 file changed

+8
-1
lines changed
 

‎eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/Narrow.scala

+8-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,14 @@ class Narrow(pipelineContext: PipelineContext) {
183183
subtype.join(t.vType, t.props.values.map(_.tp))
184184

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

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

0 commit comments

Comments
 (0)