PExpr::stype contracts are also enabled.
Signed-off-by: Jean Privat <jean@pryen.org>
meth check_expr(n: PExpr): Bool
do
if not n.is_typed then
meth check_expr(n: PExpr): Bool
do
if not n.is_typed then
+ if tc.error_count == 0 then
+ print("{n.locate} not typed but not error")
+ abort
+ end
# An error occured in a sub node,
# sillently cascade fail
return false
# An error occured in a sub node,
# sillently cascade fail
return false
- else if tc.error_count == 0 and n.is_statement then # FIXME remove 'tc.error_count == 0'
- #if tc.error_count == 0 and n.stype == null then
+ else if n.is_statement then
error(n, "Type error: expected expression.")
return false
end
error(n, "Type error: expected expression.")
return false
end
- redef readable attr _is_typed: Bool = true # FIXME: Switch to false once subclasses are adapted
+ redef readable attr _is_typed: Bool = false
redef meth is_statement: Bool do return _stype == null
redef meth stype
do
redef meth is_statement: Bool do return _stype == null
redef meth stype
do
+ if not is_typed then
+ print "{locate}: not is_typed"
+ abort
+ end
+ if is_statement then
+ print "{locate}: is_statement"
+ abort
+ end
return _stype
end
attr _stype: MMType
return _stype
end
attr _stype: MMType
v.check_conform_expr(n_expr, va.stype)
end
else
v.check_conform_expr(n_expr, va.stype)
end
else
+ if not v.check_expr(n_expr) then return
va.stype = n_expr.stype
end
va.stype = n_expr.stype
end
super
v.variable_ctx = old_var_ctx
super
v.variable_ctx = old_var_ctx
else if n_expr != null and t != null then
v.check_conform_expr(n_expr, t)
end
else if n_expr != null and t != null then
v.check_conform_expr(n_expr, t)
end
else if n_expr != null and t != null then
v.check_conform_expr(n_expr, t)
end
else if n_expr != null and t != null then
v.check_conform_expr(n_expr, t)
end
# Typing check can only be done later
bl.add(n_expr)
end
# Typing check can only be done later
bl.add(n_expr)
end
v.visit(n_else)
v.variable_ctx = old_var_ctx
end
v.visit(n_else)
v.variable_ctx = old_var_ctx
end
v.check_conform_expr(n_expr, v.type_bool)
v.escapable_ctx.pop
v.check_conform_expr(n_expr, v.type_bool)
v.escapable_ctx.pop
+ if not v.check_conform_expr(n_expr, v.type_collection) then return
var expr_type = n_expr.stype
var expr_type = n_expr.stype
- if not v.check_conform_expr(n_expr, v.type_collection) then
- return
- end
_meth_iterator = expr_type.local_class.select_method(once ("iterator".to_symbol))
if _meth_iterator == null then
v.error(self, "Error: Collection MUST have an iterate method")
_meth_iterator = expr_type.local_class.select_method(once ("iterator".to_symbol))
if _meth_iterator == null then
v.error(self, "Error: Collection MUST have an iterate method")
if n_block != null then v.visit(n_block)
# pop context
if n_block != null then v.visit(n_block)
# pop context
- var varctx = v.variable_ctx
+ var varctx = v.variable_ctx
assert varctx isa SubVariableContext
v.variable_ctx = varctx.prev
v.escapable_ctx.pop
assert varctx isa SubVariableContext
v.variable_ctx = varctx.prev
v.escapable_ctx.pop
do
v.check_conform_expr(n_expr, v.type_bool)
v.use_if_true_variable_ctx(n_expr)
do
v.check_conform_expr(n_expr, v.type_bool)
v.use_if_true_variable_ctx(n_expr)
redef meth after_typing(v)
do
_stype = v.variable_ctx.stype(variable)
redef meth after_typing(v)
do
_stype = v.variable_ctx.stype(variable)
+ _is_typed = _stype != null
do
var t = v.variable_ctx.stype(variable)
v.check_conform_expr(n_value, t)
do
var t = v.variable_ctx.stype(variable)
v.check_conform_expr(n_value, t)
prop.global.check_visibility(v, self, v.module, false)
var psig = prop.signature_for(type_lvalue)
_assign_method = prop
prop.global.check_visibility(v, self, v.module, false)
var psig = prop.signature_for(type_lvalue)
_assign_method = prop
- v.check_conform_expr(n_value, psig[0].not_for_self)
- v.check_conform(self, psig.return_type.not_for_self, n_value.stype)
+ if not v.check_conform_expr(n_value, psig[0].not_for_self) then return
+ if not v.check_conform(self, psig.return_type.not_for_self, n_value.stype) then return
end
# Method used through the reassigment operator (once computed)
end
# Method used through the reassigment operator (once computed)
do
var t = v.variable_ctx.stype(variable)
do_lvalue_typing(v, t)
do
var t = v.variable_ctx.stype(variable)
do_lvalue_typing(v, t)
do
variable = v.self_var
_stype = v.variable_ctx.stype(variable)
do
variable = v.self_var
_stype = v.variable_ctx.stype(variable)
end
redef meth is_self do return true
end
redef meth is_self do return true
v.check_conform_expr(n_expr, v.type_bool)
_stype = v.check_conform_multiexpr(null, [n_then, n_else])
v.check_conform_expr(n_expr, v.type_bool)
_stype = v.check_conform_multiexpr(null, [n_then, n_else])
+ _is_typed = _stype != null
redef meth after_typing(v)
do
_stype = v.type_bool
redef meth after_typing(v)
do
_stype = v.type_bool
v.check_conform_expr(n_expr, v.type_bool)
v.check_conform_expr(n_expr2, v.type_bool)
_stype = v.type_bool
v.check_conform_expr(n_expr, v.type_bool)
v.check_conform_expr(n_expr2, v.type_bool)
_stype = v.type_bool
v.check_conform_expr(n_expr, v.type_bool)
v.check_conform_expr(n_expr2, v.type_bool)
_stype = v.type_bool
v.check_conform_expr(n_expr, v.type_bool)
v.check_conform_expr(n_expr2, v.type_bool)
_stype = v.type_bool
do
v.check_conform_expr(n_expr, v.type_bool)
_stype = v.type_bool
do
v.check_conform_expr(n_expr, v.type_bool)
_stype = v.type_bool
redef meth after_typing(v)
do
_stype = v.type_int
redef meth after_typing(v)
do
_stype = v.type_int
redef meth after_typing(v)
do
_stype = v.type_float
redef meth after_typing(v)
do
_stype = v.type_float
redef meth after_typing(v)
do
_stype = v.type_char
redef meth after_typing(v)
do
_stype = v.type_char
redef meth after_typing(v)
do
_stype = v.type_string
redef meth after_typing(v)
do
_stype = v.type_string
_meth_with_native = _stype.local_class.select_method(once "with_native".to_symbol)
if _meth_with_native == null then v.error(self, "{_stype} MUST have a with_native method.")
end
_meth_with_native = _stype.local_class.select_method(once "with_native".to_symbol)
if _meth_with_native == null then v.error(self, "{_stype} MUST have a with_native method.")
end
if _meth_add == null then v.error(self, "{_atype} MUST have an add method.")
_meth_to_s = v.type_object.local_class.select_method(once "to_s".to_symbol)
if _meth_to_s == null then v.error(self, "Object MUST have a to_s method.")
if _meth_add == null then v.error(self, "{_atype} MUST have an add method.")
_meth_to_s = v.type_object.local_class.select_method(once "to_s".to_symbol)
if _meth_to_s == null then v.error(self, "Object MUST have a to_s method.")
redef meth after_typing(v)
do
_stype = v.type_none
redef meth after_typing(v)
do
_stype = v.type_none
if _meth_with_capacity == null then v.error(self, "{_stype} MUST have a with_capacity method.")
_meth_add = _stype.local_class.select_method(once "add".to_symbol)
if _meth_add == null then v.error(self, "{_stype} MUST have an add method.")
if _meth_with_capacity == null then v.error(self, "{_stype} MUST have a with_capacity method.")
_meth_add = _stype.local_class.select_method(once "add".to_symbol)
if _meth_add == null then v.error(self, "{_stype} MUST have an add method.")
readable attr _meth_init: MMMethod
redef meth after_typing(v)
do
readable attr _meth_init: MMMethod
redef meth after_typing(v)
do
+ if not v.check_expr(n_expr) or not v.check_expr(n_expr2) then return
var ntype = n_expr.stype
var ntype2 = n_expr2.stype
var ntype = n_expr.stype
var ntype2 = n_expr2.stype
- if ntype == null or ntype == null then
- return
- end
if ntype < ntype2 then
ntype = ntype2
else if not ntype2 < ntype then
if ntype < ntype2 then
ntype = ntype2
else if not ntype2 < ntype then
return
end
var dtype = v.type_discrete
return
end
var dtype = v.type_discrete
- v.check_conform_expr(n_expr, dtype)
- v.check_conform_expr(n_expr2, dtype)
+ if not v.check_conform_expr(n_expr, dtype) or not v.check_conform_expr(n_expr2, dtype) then return
_stype = v.type_range(ntype)
_stype = v.type_range(ntype)
var p = v.local_property
assert p isa MMSrcMethod
_prop = p
var p = v.local_property
assert p isa MMSrcMethod
_prop = p
redef meth after_typing(v)
do
do_typing(v)
redef meth after_typing(v)
do
do_typing(v)
- if prop == null then
- return
- end
+ if prop == null then return
redef meth after_typing(v)
do
do_typing(v)
redef meth after_typing(v)
do
do_typing(v)
- if prop == null then
- return
- end
- v.check_conform_expr(n_value, attr_type)
+ if prop == null then return
+ if not v.check_conform_expr(n_value, attr_type) then return
+ _is_typed = true
redef meth after_typing(v)
do
do_typing(v)
redef meth after_typing(v)
do
do_typing(v)
- if prop == null then
- return
- end
+ if prop == null then return
do_lvalue_typing(v, attr_type)
do_lvalue_typing(v, attr_type)
var args = process_signature(v, sig, prop.name, raw_args)
if args == null then return
var rtype = process_closures(v, sig, prop.name, closure_defs)
var args = process_signature(v, sig, prop.name, raw_args)
if args == null then return
var rtype = process_closures(v, sig, prop.name, closure_defs)
+ if rtype == null and sig.return_type != null then return
_prop = prop
_prop_signature = sig
_arguments = args
_prop = prop
_prop_signature = sig
_arguments = args
if not prop.global.is_init then
v.error(self, "Error: {prop} is not a constructor.")
if not prop.global.is_init then
v.error(self, "Error: {prop} is not a constructor.")
end
_arguments = old_args # FIXME: What if star parameters do not match betwen the two methods?
end
_arguments = old_args # FIXME: What if star parameters do not match betwen the two methods?
_prop_signature = sig
_arguments = args
_stype = sig.return_type
_prop_signature = sig
_arguments = args
_stype = sig.return_type
_if_true_variable_ctx = v.variable_ctx.sub_with(variable, n_type.stype)
end
_stype = v.type_bool
_if_true_variable_ctx = v.variable_ctx.sub_with(variable, n_type.stype)
end
_stype = v.type_bool
do
v.check_expr(n_expr)
_stype = n_type.stype
do
v.check_expr(n_expr)
_stype = n_type.stype
+ _is_typed = _stype != null
end
end
redef class AProxyExpr
redef meth after_typing(v)
do
end
end
redef class AProxyExpr
redef meth after_typing(v)
do
+ if not n_expr.is_typed then return
+ _is_typed = true
+ if n_expr.is_statement then return
_stype = n_expr.stype
end
end
_stype = n_expr.stype
end
end