niti: all fatal errors are catchable, not just aborts
[nit.git] / src / interpreter / naive_interpreter.nit
index c4f7ac3..66afa45 100644 (file)
@@ -353,7 +353,7 @@ class NaiveInterpreter
        fun string_instance(txt: String): Instance
        do
                var nat = c_string_instance(txt)
-               var res = self.send(self.force_get_primitive_method("to_s_full", nat.mtype), [nat, self.int_instance(txt.byte_length), self.int_instance(txt.length)])
+               var res = self.send(self.force_get_primitive_method("to_s_unsafe", nat.mtype), [nat, self.int_instance(txt.byte_length), self.int_instance(txt.length), self.false_instance, self.false_instance])
                assert res != null
                return res
        end
@@ -691,9 +691,10 @@ abstract class Instance
        # ASSERT: not self.mtype.is_anchored
        var mtype: MType
 
-       # return true if the instance is the true value.
-       # return false if the instance is the true value.
-       # else aborts
+       # Return `true` if the instance is the `true` value.
+       #
+       # Return `false` if the instance is the `false` value.
+       # Abort if the instance is not a boolean value.
        fun is_true: Bool do abort
 
        # Return true if `self` IS `o` (using the Nit semantic of is)
@@ -748,7 +749,7 @@ class MutableInstance
 end
 
 # Special instance to handle primitives values (int, bool, etc.)
-# The trick it just to encapsulate the <<real>> value
+# The trick is just to encapsulate the “real” value.
 class PrimitiveInstance[E]
        super Instance
 
@@ -820,6 +821,11 @@ redef class ANode
        # `v` is used to know if a colored message is displayed or not
        fun fatal(v: NaiveInterpreter, message: String)
        do
+               # Abort if there is a `catch` block
+               if v.catch_count > 0 then
+                       abort
+               end
+
                if v.modelbuilder.toolcontext.opt_no_color.value == true then
                        sys.stderr.write("Runtime error: {message} ({location.file.filename}:{location.line_start})\n")
                else
@@ -1174,9 +1180,9 @@ redef class AMethPropdef
                                var ns = recvval.fast_cstring(args[1].to_i)
                                return v.c_string_instance(ns.to_s)
                        else if pname == "fetch_4_chars" then
-                               return v.int_instance(args[0].val.as(CString).fetch_4_chars(args[1].to_i))
+                               return v.uint32_instance(args[0].val.as(CString).fetch_4_chars(args[1].to_i))
                        else if pname == "fetch_4_hchars" then
-                               return v.int_instance(args[0].val.as(CString).fetch_4_hchars(args[1].to_i))
+                               return v.uint32_instance(args[0].val.as(CString).fetch_4_hchars(args[1].to_i))
                        else if pname == "utf8_length" then
                                return v.int_instance(args[0].val.as(CString).utf8_length(args[1].to_i, args[2].to_i))
                        end
@@ -1688,13 +1694,8 @@ end
 redef class AAbortExpr
        redef fun stmt(v)
        do
-               # Abort as asked if there is no `catch` bloc
-               if v.catch_count <= 0 then
-                       fatal(v, "Aborted")
-                       exit(1)
-               else
-                       abort
-               end
+               fatal(v, "Aborted")
+               exit(1)
        end
 end