Skip to content

Commit f99611a

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Remove TypingOracle::as_function
Summary: Treat any `TyName` as not callable. Reviewed By: cjhopman Differential Revision: D48932756 fbshipit-source-id: daa87413a646b79b3e21f18b8503d93fbb29ae88
1 parent 4563bc9 commit f99611a

File tree

6 files changed

+7
-119
lines changed

6 files changed

+7
-119
lines changed

starlark/src/typing/golden/call_callable_or_unknown.golden

Lines changed: 0 additions & 17 deletions
This file was deleted.

starlark/src/typing/golden/call_not_callable_or_unknown.golden

Lines changed: 0 additions & 17 deletions
This file was deleted.

starlark/src/typing/golden/call_unknown.golden

Lines changed: 0 additions & 16 deletions
This file was deleted.

starlark/src/typing/oracle/ctx.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,19 +284,12 @@ impl<'a> TypingOracleCtx<'a> {
284284
&self,
285285
span: Span,
286286
ty: &TyName,
287-
args: &[Spanned<Arg>],
287+
_args: &[Spanned<Arg>],
288288
) -> Result<Ty, TypingOrInternalError> {
289-
match self.oracle.as_function(ty) {
290-
None => {
291-
// Unknown type, may be callable.
292-
Ok(Ty::any())
293-
}
294-
Some(Ok(f)) => self.validate_fn_call(span, &f, args),
295-
Some(Err(())) => Err(self.mk_error_as_maybe_internal(
296-
span,
297-
TypingOracleCtxError::CallToNonCallable { ty: ty.to_string() },
298-
)),
299-
}
289+
Err(self.mk_error_as_maybe_internal(
290+
span,
291+
TypingOracleCtxError::CallToNonCallable { ty: ty.to_string() },
292+
))
300293
}
301294

302295
#[allow(clippy::collapsible_else_if)]

starlark/src/typing/oracle/traits.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
use dupe::Dupe;
2222

23-
use crate::typing::function::TyFunction;
2423
use crate::typing::ty::Ty;
2524
use crate::typing::ty::TyName;
2625

@@ -102,11 +101,6 @@ pub trait TypingOracle {
102101
None
103102
}
104103

105-
/// If type is callable, return it as function signature.
106-
fn as_function(&self, ty: &TyName) -> Option<Result<TyFunction, ()>> {
107-
None
108-
}
109-
110104
/// If we require the first type, but got the second type, is that OK?
111105
/// Usually its OK if the requirement is a subtype of the one we got.
112106
fn subtype(&self, require: &TyName, got: &TyName) -> bool {
@@ -135,10 +129,6 @@ impl<T: TypingOracle> TypingOracle for OracleSeq<T> {
135129
self.0.iter().find_map(|oracle| oracle.attribute(ty, attr))
136130
}
137131

138-
fn as_function(&self, ty: &TyName) -> Option<Result<TyFunction, ()>> {
139-
self.0.iter().find_map(|oracle| oracle.as_function(ty))
140-
}
141-
142132
fn subtype(&self, require: &TyName, got: &TyName) -> bool {
143133
self.0.iter().any(|oracle| oracle.subtype(require, got))
144134
}
@@ -154,9 +144,7 @@ impl<'a, T: TypingOracle + ?Sized> TypingOracle for &'a T {
154144
fn attribute(&self, ty: &TyName, attr: &str) -> Option<Result<Ty, ()>> {
155145
(*self).attribute(ty, attr)
156146
}
157-
fn as_function(&self, ty: &TyName) -> Option<Result<TyFunction, ()>> {
158-
(*self).as_function(ty)
159-
}
147+
160148
fn subtype(&self, require: &TyName, got: &TyName) -> bool {
161149
(*self).subtype(require, got)
162150
}
@@ -166,9 +154,7 @@ impl<T: TypingOracle + ?Sized> TypingOracle for Box<T> {
166154
fn attribute(&self, ty: &TyName, attr: &str) -> Option<Result<Ty, ()>> {
167155
self.as_ref().attribute(ty, attr)
168156
}
169-
fn as_function(&self, ty: &TyName) -> Option<Result<TyFunction, ()>> {
170-
self.as_ref().as_function(ty)
171-
}
157+
172158
fn subtype(&self, require: &TyName, got: &TyName) -> bool {
173159
self.as_ref().subtype(require, got)
174160
}

starlark/src/typing/tests.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -327,19 +327,6 @@ def foo(x: list):
327327
);
328328
}
329329

330-
#[test]
331-
fn test_call_unknown() {
332-
TypeCheck::new().check(
333-
"call_unknown",
334-
r#"
335-
# @starlark-rust: allow_string_literals_in_type_expr
336-
337-
def foo(x: "unknown"):
338-
x()
339-
"#,
340-
);
341-
}
342-
343330
#[test]
344331
fn test_call_callable_or_not_callable() {
345332
TypeCheck::new().check(
@@ -352,34 +339,6 @@ def foo(x: [typing.Callable, str], y: [str, typing.Callable]):
352339
);
353340
}
354341

355-
#[test]
356-
fn test_call_callable_or_unknown() {
357-
TypeCheck::new().check(
358-
"call_callable_or_unknown",
359-
r#"
360-
# @starlark-rust: allow_string_literals_in_type_expr
361-
362-
def foo(x: [typing.Callable, "unknown"], y: ["unknown", typing.Callable]):
363-
x()
364-
y()
365-
"#,
366-
);
367-
}
368-
369-
#[test]
370-
fn test_call_not_callable_or_unknown() {
371-
TypeCheck::new().check(
372-
"call_not_callable_or_unknown",
373-
r#"
374-
# @starlark-rust: allow_string_literals_in_type_expr
375-
376-
def foo(x: [str, "unknown"], y: ["unknown", str]):
377-
x()
378-
y()
379-
"#,
380-
);
381-
}
382-
383342
#[test]
384343
fn test_tuple() {
385344
TypeCheck::new().check(

0 commit comments

Comments
 (0)