# --no-check-assert
var opt_no_check_assert: OptionBool = new OptionBool("Disable the evaluation of explicit 'assert' and 'as' (dangerous)", "--no-check-assert")
+ # --no-check-autocast
+ var opt_no_check_autocast: OptionBool = new OptionBool("Disable implicit casts on unsafe expression usage (dangerous)", "--no-check-autocast")
+
# --no-check-other
var opt_no_check_other: OptionBool = new OptionBool("Disable implicit tests: unset attribute, null receiver (dangerous)", "--no-check-other")
do
super
self.option_context.add_option(self.opt_output, self.opt_no_cc, self.opt_hardening)
- self.option_context.add_option(self.opt_no_check_covariance, self.opt_no_check_initialization, self.opt_no_check_assert, self.opt_no_check_other)
+ self.option_context.add_option(self.opt_no_check_covariance, self.opt_no_check_initialization, self.opt_no_check_assert, self.opt_no_check_autocast, self.opt_no_check_other)
end
end
mtype = self.anchor(mtype)
res = self.autobox(res, mtype)
end
+ var implicit_cast_to = nexpr.implicit_cast_to
+ if implicit_cast_to != null and not self.compiler.modelbuilder.toolcontext.opt_no_check_autocast.value then
+ var castres = self.type_test(res, implicit_cast_to)
+ self.add("if (!{castres}) \{")
+ self.add_abort("Cast failed")
+ self.add("\}")
+ end
self.current_node = old
return res
end