@@ -23,8 +23,6 @@ import middle::ty::pat_ty;
23
23
import middle:: ty:: path_to_str;
24
24
import middle:: ty:: ty_param_substs_opt_and_ty;
25
25
import middle:: ty:: ty_to_str;
26
- import middle:: ty:: type_is_integral;
27
- import middle:: ty:: type_is_scalar;
28
26
import middle:: ty:: ty_param_count_and_ty;
29
27
import middle:: ty:: ty_nil;
30
28
import middle:: ty:: unify:: ures_ok;
@@ -76,22 +74,16 @@ fn ty_param_count_and_ty_for_def(&@fn_ctxt fcx, &span sp, &ast::def defn)
76
74
case ( ast:: def_arg ( ?id) ) {
77
75
assert ( fcx. locals . contains_key ( id) ) ;
78
76
auto typ = ty:: mk_var ( fcx. ccx . tcx , fcx. locals . get ( id) ) ;
79
- typ = ty:: unify:: resolve_all_vars ( fcx. ccx . tcx , fcx. var_bindings ,
80
- typ) ;
81
77
ret tup( 0 u, typ) ;
82
78
}
83
79
case ( ast:: def_local ( ?id) ) {
84
80
assert ( fcx. locals . contains_key ( id) ) ;
85
81
auto typ = ty:: mk_var ( fcx. ccx . tcx , fcx. locals . get ( id) ) ;
86
- typ = ty:: unify:: resolve_all_vars ( fcx. ccx . tcx , fcx. var_bindings ,
87
- typ) ;
88
82
ret tup( 0 u, typ) ;
89
83
}
90
84
case ( ast:: def_obj_field ( ?id) ) {
91
85
assert ( fcx. locals . contains_key ( id) ) ;
92
86
auto typ = ty:: mk_var ( fcx. ccx . tcx , fcx. locals . get ( id) ) ;
93
- typ = ty:: unify:: resolve_all_vars ( fcx. ccx . tcx , fcx. var_bindings ,
94
- typ) ;
95
87
ret tup( 0 u, typ) ;
96
88
}
97
89
case ( ast:: def_fn ( ?id) ) {
@@ -109,8 +101,6 @@ fn ty_param_count_and_ty_for_def(&@fn_ctxt fcx, &span sp, &ast::def defn)
109
101
case ( ast:: def_binding ( ?id) ) {
110
102
assert ( fcx. locals . contains_key ( id) ) ;
111
103
auto typ = ty:: mk_var ( fcx. ccx . tcx , fcx. locals . get ( id) ) ;
112
- typ = ty:: unify:: resolve_all_vars ( fcx. ccx . tcx , fcx. var_bindings ,
113
- typ) ;
114
104
ret tup( 0 u, typ) ;
115
105
}
116
106
case ( ast:: def_obj ( ?id) ) {
@@ -194,19 +184,37 @@ fn ast_mode_to_mode(ast::mode mode) -> ty::mode {
194
184
ret ty_mode;
195
185
}
196
186
197
- // Returns the one-level-deep structure of the given type.
198
- fn structure_of ( & @fn_ctxt fcx , & span sp, ty:: t typ ) -> ty:: sty {
187
+
188
+ // Type tests
189
+
190
+ fn structurally_resolved_type ( & @fn_ctxt fcx , & span sp, ty:: t typ ) -> ty:: t {
199
191
auto r = ty:: unify:: resolve_type_structure ( fcx. ccx . tcx , fcx. var_bindings ,
200
192
typ) ;
201
193
alt ( r) {
202
- case ( fix_ok ( ?typ_s) ) { ret ty :: struct ( fcx . ccx . tcx , typ_s) ; }
194
+ case ( fix_ok ( ?typ_s) ) { ret typ_s; }
203
195
case ( fix_err ( _) ) {
204
196
fcx. ccx . tcx . sess . span_err ( sp, "the type of this value must be " +
205
197
"known in this context" ) ;
206
198
}
207
199
}
208
200
}
209
201
202
+ // Returns the one-level-deep structure of the given type.
203
+ fn structure_of ( & @fn_ctxt fcx , & span sp, ty:: t typ ) -> ty:: sty {
204
+ ret ty:: struct ( fcx. ccx . tcx , structurally_resolved_type ( fcx, sp, typ) ) ;
205
+ }
206
+
207
+ fn type_is_integral ( & @fn_ctxt fcx , & span sp, ty:: t typ ) -> bool {
208
+ auto typ_s = structurally_resolved_type ( fcx, sp, typ) ;
209
+ ret ty:: type_is_integral ( fcx. ccx . tcx , typ_s) ;
210
+ }
211
+
212
+ fn type_is_scalar ( & @fn_ctxt fcx , & span sp, ty:: t typ ) -> bool {
213
+ auto typ_s = structurally_resolved_type ( fcx, sp, typ) ;
214
+ ret ty:: type_is_scalar ( fcx. ccx . tcx , typ_s) ;
215
+ }
216
+
217
+
210
218
// Parses the programmer's textual representation of a type into our internal
211
219
// notion of a type. `getter` is a function that returns the type
212
220
// corresponding to a definition ID:
@@ -1984,9 +1992,8 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
1984
1992
check_expr( fcx, e) ;
1985
1993
auto t_1 = ast_ty_to_ty_crate( fcx. ccx, t) ;
1986
1994
// FIXME: there are more forms of cast to support, eventually.
1987
- if ( ! ( type_is_scalar( fcx. ccx. tcx,
1988
- expr_ty( fcx. ccx. tcx, e) ) &&
1989
- type_is_scalar( fcx. ccx. tcx, t_1) ) ) {
1995
+ if ( ! ( type_is_scalar( fcx, expr. span, expr_ty( fcx. ccx. tcx, e) ) &&
1996
+ type_is_scalar( fcx, expr. span, t_1) ) ) {
1990
1997
fcx. ccx. tcx. sess. span_err( expr. span,
1991
1998
"non-scalar cast: " +
1992
1999
ty_to_str( fcx. ccx. tcx,
@@ -2148,7 +2155,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
2148
2155
auto idx_t = expr_ty( fcx. ccx. tcx, idx) ;
2149
2156
alt ( structure_of( fcx, expr. span, base_t) ) {
2150
2157
case ( ty:: ty_vec( ?mt) ) {
2151
- if ( ! type_is_integral( fcx. ccx . tcx , idx_t) ) {
2158
+ if ( ! type_is_integral( fcx, idx . span , idx_t) ) {
2152
2159
fcx. ccx. tcx. sess. span_err
2153
2160
( idx. span,
2154
2161
"non-integral type of vec index: "
@@ -2157,7 +2164,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
2157
2164
write:: ty_only_fixup( fcx, a. id, mt. ty) ;
2158
2165
}
2159
2166
case ( ty:: ty_str) {
2160
- if ( ! type_is_integral( fcx. ccx . tcx , idx_t) ) {
2167
+ if ( ! type_is_integral( fcx, idx . span , idx_t) ) {
2161
2168
fcx. ccx. tcx. sess. span_err
2162
2169
( idx. span,
2163
2170
"non-integral type of str index: "
0 commit comments