enable class constants in folded classes
[hiphop-php.git] / hphp / hack / src / rupro / lib / typing_return.rs
blob0a045e12692cf2432a4c69cc73642e4a9c61437d
1 // Copyright (c) Facebook, Inc. and its affiliates.
2 //
3 // This source code is licensed under the MIT license found in the
4 // LICENSE file in the "hack" directory of this source tree.
6 #![allow(dead_code)]
7 use crate::alloc::Allocator;
8 use crate::decl_defs::DeclTy;
9 use crate::reason::{Reason, ReasonImpl};
10 use crate::typing_defs::Ty;
11 use crate::typing_env::TEnv;
12 use pos::Symbol;
14 pub struct TypingReturn;
16 #[derive(Debug, Clone)]
17 pub struct TypingReturnInfo<R: Reason> {
18     return_type: Ty<R>,
21 impl TypingReturn {
22     pub fn make_default_return<R: Reason>(
23         env: &TEnv<R>,
24         is_method: bool,
25         fpos: &R::Pos,
26         fname: Symbol,
27     ) -> Ty<R> {
28         let reason = R::mk(|| ReasonImpl::Rwitness(fpos.clone()));
29         if is_method && fname == env.ctx.special_names.members.__construct {
30             env.ctx.alloc.ty_void(reason)
31         } else {
32             env.ctx.alloc.tany(reason)
33         }
34     }
36     pub fn make_return_type<R: Reason>(
37         env: &TEnv<R>,
38         localize: &dyn Fn(&TEnv<R>, DeclTy<R>) -> Ty<R>,
39         ty: DeclTy<R>,
40     ) -> Ty<R> {
41         // TODO(hrust): async
42         localize(env, ty)
43     }
45     pub fn make_info<R: Reason>(
46         _env: &TEnv<R>,
47         _ret_pos: R::Pos,
48         _fun_kind: &oxidized::ast_defs::FunKind,
49         _attributes: &[oxidized::aast::UserAttribute<(), ()>],
50         _is_explicit: bool,
51         locl_ty: Ty<R>,
52         _decl_ty: Option<DeclTy<R>>,
53     ) -> TypingReturnInfo<R> {
54         // TODO(hrust): everything
55         TypingReturnInfo {
56             return_type: locl_ty,
57         }
58     }
61 impl<R: Reason> TypingReturnInfo<R> {
62     pub fn placeholder(alloc: &Allocator<R>) -> Self {
63         // TODO(hrust): Tunion []
64         Self {
65             return_type: alloc.tany(R::mk(|| ReasonImpl::Rnone)),
66         }
67     }