Skip to content

Commit 613471b

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Make TyBasic::List intersect with TyStarlarkValue::new::<List>
Summary: I'm not sure whether we should allow `TyStarlarkValue::new::<List>`. Allow it for now, and make intersect work. Safe anyway. Reviewed By: ianlevesque Differential Revision: D48935562 fbshipit-source-id: 67226088df6e289e0e95767530ad55a46db12abd
1 parent 9593fde commit 613471b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

starlark/src/typing/oracle/ctx.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,11 +833,13 @@ impl<'a> TypingOracleCtx<'a> {
833833
(TyBasic::Name(_), TyBasic::StarlarkValue(_)) => true,
834834
(TyBasic::Name(x), y) => Some(x.as_str()) == y.as_name(),
835835
(TyBasic::List(x), TyBasic::List(y)) => self.intersects(x, y),
836+
(TyBasic::List(_), TyBasic::StarlarkValue(y)) => y.is_list(),
836837
(TyBasic::Dict(x_k, x_v), TyBasic::Dict(y_k, y_v)) => {
837838
self.intersects(x_k, y_k) && self.intersects(x_v, y_v)
838839
}
840+
(TyBasic::Dict(..), TyBasic::StarlarkValue(y)) => y.is_dict(),
839841
(TyBasic::Tuple(x), TyBasic::Tuple(y)) => TyTuple::intersects(x, y, self),
840-
(TyBasic::Tuple(_), t) => t.is_tuple(),
842+
(TyBasic::Tuple(_), TyBasic::StarlarkValue(y)) => y.is_tuple(),
841843
(TyBasic::Iter(x), TyBasic::Iter(y)) => self.intersects(x, y),
842844
(TyBasic::Iter(x), y) | (y, TyBasic::Iter(x)) => match self.iter_item_basic(y) {
843845
Ok(yy) => self.intersects(x, &yy),

starlark/src/typing/starlark_value.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ use crate::typing::TypingBinOp;
3535
use crate::typing::TypingOracleCtx;
3636
use crate::typing::TypingUnOp;
3737
use crate::values::bool::StarlarkBool;
38+
use crate::values::dict::value::FrozenDict;
3839
use crate::values::float::StarlarkFloat;
40+
use crate::values::list::value::FrozenList;
3941
use crate::values::none::NoneType;
4042
use crate::values::starlark_type_id::StarlarkTypeId;
4143
use crate::values::string::StarlarkStr;
@@ -180,6 +182,21 @@ impl TyStarlarkValue {
180182
self == TyStarlarkValue::new::<StarlarkBigInt>()
181183
}
182184

185+
pub(crate) fn is_list(self) -> bool {
186+
self.self_check();
187+
self == TyStarlarkValue::new::<FrozenList>()
188+
}
189+
190+
pub(crate) fn is_dict(self) -> bool {
191+
self.self_check();
192+
self == TyStarlarkValue::new::<FrozenDict>()
193+
}
194+
195+
pub(crate) fn is_tuple(self) -> bool {
196+
self.self_check();
197+
self == TyStarlarkValue::new::<Tuple>()
198+
}
199+
183200
/// Result of applying unary operator to this type.
184201
pub(crate) fn un_op(self, un_op: TypingUnOp) -> Result<TyStarlarkValue, ()> {
185202
let has = match un_op {

0 commit comments

Comments
 (0)