about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2011-07-03 02:33:35 -0400
committerBrian Anderson <banderson@mozilla.com>2011-07-03 21:46:17 -0700
commita2775a5b72b7cad1bfe2a480a79bfe48281dd40f (patch)
treefbf0b50b1039915b40b96d9d4c40ce6c8bb91906 /src/comp
parentb110bbf886fd2d9d99c6e66b084ebd2430c57fe3 (diff)
downloadrust-a2775a5b72b7cad1bfe2a480a79bfe48281dd40f.tar.gz
rust-a2775a5b72b7cad1bfe2a480a79bfe48281dd40f.zip
Make non-str fail expression a type checking failure instead of a translation one.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/trans.rs6
-rw-r--r--src/comp/middle/typeck.rs17
2 files changed, 19 insertions, 4 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 44cab2120a0..8797d05a51f 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -6388,9 +6388,9 @@ fn trans_fail_expr(&@block_ctxt cx, &option::t[common::span] sp_opt,
                                         [C_int(0), C_int(abi::vec_elt_data)]);
                 ret trans_fail_value(bcx, sp_opt, elt);
             } else {
-                bcx.fcx.lcx.ccx.sess.span_fatal(expr.span,
-                                               "fail called with unsupported \
-                                               type " + ty_to_str(tcx, e_ty));
+                cx.fcx.lcx.ccx.sess.span_bug(expr.span,
+                                             "fail called with unsupported \
+                                              type " + ty_to_str(tcx, e_ty));
             }
         }
         case (_) {
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index 41c3ff993ee..6fbe6493061 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -229,6 +229,11 @@ fn type_is_scalar(&@fn_ctxt fcx, &span sp, ty::t typ) -> bool {
     ret ty::type_is_scalar(fcx.ccx.tcx, typ_s);
 }
 
+fn type_is_str(&@fn_ctxt fcx, &span sp, ty::t typ) -> bool {
+    auto typ_s = structurally_resolved_type(fcx, sp, typ);
+    ret ty::type_is_str(fcx.ccx.tcx, typ_s);    
+}
+
 
 // Parses the programmer's textual representation of a type into our internal
 // notion of a type. `getter` is a function that returns the type
@@ -1658,7 +1663,17 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
         case (ast::expr_fail(?expr_opt)) {
             alt (expr_opt) {
                 case (none) { /* do nothing */ }
-                case (some(?e)) { check_expr(fcx, e); }
+                case (some(?e)) {
+                    check_expr(fcx, e);
+                    auto tcx = fcx.ccx.tcx;
+                    auto ety = expr_ty(tcx, e);
+                    if (!type_is_str(fcx, e.span, ety)) {
+                        tcx.sess.span_fatal(e.span,
+                                            #fmt("mismatched types: expected \
+                                                  str, found %s",
+                                                 ty_to_str(tcx, ety)));
+                    }
+                }
             }
             write::bot_ty(fcx.ccx.tcx, id);
         }