<keyword>fun</keyword>
<keyword>redef</keyword>
<keyword>var</keyword>
- <keyword>package</keyword>
<keyword>module</keyword>
<keyword>type</keyword>
<keyword>universal</keyword>
# Return true if the string writer is frozen
readable var _is_frozen: Bool = false
- # Disable funter writer modification: nor add or append are allowed
+ # Disable further writer modification: nor add or append are allowed
fun freeze
do
if is_frozen then return
end
end
+class MMParam
+ readable var _mmtype: MMType
+ readable var _name: Symbol
+
+ init ( t : MMType, n : Symbol )
+ do
+ _mmtype = t
+ _name = n
+ end
+
+ redef fun to_s do return "{name}: {mmtype}"
+end
+
# Signature for local properties
class MMSignature
# The type of the reveiver
readable var _recv: MMType
# The parameter types
- var _params: Array[MMType]
+ readable var _params: Array[MMParam]
# The return type
readable var _return_type: nullable MMType
fun [](i: Int): MMType
do
assert _params.length > i
- return _params[i]
+ return _params[i].mmtype
end
redef fun to_s
var tmp: String
var a = new Array[String].with_capacity(_params.length)
for i in [0.._params.length[ do
- #var pn = _params_name[i]
var p = _params[i]
- #a.add("{pn}: {p}")
a.add(p.to_s)
end
- s.append("({a.join(",")})")
+ s.append("({a.join(", ")})")
end
var rt = _return_type
if rt != null then s.append(": {rt}")
return self
end
var mod = r.mmmodule
- var p = new Array[MMType]
+ var p = new Array[MMParam]
for i in _params do
- p.add(i.for_module(mod).adapt_to(r))
+ var new_type = i.mmtype.for_module(mod).adapt_to(r)
+ var new_param
+ if new_type == i.mmtype then
+ new_param = i
+ else
+ new_param = new MMParam( new_type, i.name )
+ end
+
+ p.add( new_param )
end
var rv = _return_type
if rv != null then
if _not_for_self_cache != null then return _not_for_self_cache.as(not null)
var need_for_self = false
- var p = new Array[MMType]
+ var p = new Array[MMParam]
for i in _params do
- var i2 = i.not_for_self
- if i != i2 then need_for_self = true
- p.add(i2)
+ var new_type = i.mmtype.not_for_self
+ var new_param
+ if i.mmtype == new_type then
+ new_param = i
+ else
+ need_for_self = true
+ new_param = new MMParam( new_type, i.name )
+ end
+
+ p.add( new_param )
end
var rv = _return_type
return res
end
- init(params: Array[MMType], return_type: nullable MMType, r: MMType)
+ init(params: Array[MMParam], return_type: nullable MMType, r: MMType)
do
_params = params
_return_type = return_type
end
# A static type
-# Note that static type a related to a specific module
+# Note that static type is related to a specific module
abstract class MMType
# The module where self makes sence
fun mmmodule: MMModule is abstract
end
_super_init = base
- var params = new Array[MMType]
+ var params = new Array[MMParam]
if base != null then
var sig = base.signature
for i in [0..sig.arity[ do
- params.add(sig[i])
+ params.add(sig.params[i])
end
end
for a in unassigned_attributes do
var sig = a.signature
if sig == null then return # Broken attribute definition
- params.add(sig.return_type.as(not null))
+ params.add( new MMParam( sig.return_type.as(not null), once "recv".to_symbol))
end
signature = new MMSignature(params, null, local_class.get_type)
end
redef fun accept_class_builder(v)
do
if n_id.to_symbol != v.mmmodule.name then
- v.error(n_id, "Error: Module name missmatch between {v.mmmodule.name} and {n_id.to_symbol}")
+ v.error(n_id, "Error: Module name mismatch between {v.mmmodule.name} and {n_id.to_symbol}")
end
end
end
do
return n_formaldefs.length
end
+ redef fun accept_class_verifier(v)
+ do
+ super
+ var glob = _local_class.global
+ if glob.intro == _local_class then
+ # Intro
+ glob.visibility_level = visibility_level
+ glob.is_interface = n_classkind.is_interface
+ glob.is_abstract = n_classkind.is_abstract
+ glob.is_enum = n_classkind.is_enum
+ if n_kwredef != null then
+ v.error(self, "Redef error: No class {name} is imported. Remove the redef keyword to define a new class.")
+ end
+
+ for c in _local_class.cshe.direct_greaters do
+ var cg = c.global
+ if glob.is_interface then
+ if cg.is_enum then
+ v.error(self, "Special error: Interface {name} try to specialise enum class {c.name}.")
+ else if not cg.is_interface then
+ v.error(self, "Special error: Interface {name} try to specialise class {c.name}.")
+ end
+ else if glob.is_enum then
+ if not cg.is_interface and not cg.is_enum then
+ v.error(self, "Special error: Enum class {name} try to specialise class {c.name}.")
+ end
+ else
+ if cg.is_enum then
+ v.error(self, "Special error: Class {name} try to specialise enum class {c.name}.")
+ end
+ end
+
+ end
+ return
+ end
+
+ # Redef
+
+ glob.check_visibility(v, self, v.mmmodule)
+ if n_kwredef == null then
+ v.error(self, "Redef error: {name} is an imported class. Add the redef keyword to refine it.")
+ return
+ end
+
+ if glob.intro.arity != _local_class.arity then
+ v.error(self, "Redef error: Formal parameter arity mismatch; got {_local_class.arity}, expected {glob.intro.arity}.")
+ end
+
+ if
+ not glob.is_interface and n_classkind.is_interface or
+ not glob.is_abstract and n_classkind.is_abstract or
+ not glob.is_enum and n_classkind.is_enum
+ then
+ v.error(self, "Redef error: cannot change kind of class {name}.")
+ end
+ end
redef fun visibility_level
do
else if not v.signature_builder.untyped_params.is_empty then
v.error(v.signature_builder.untyped_params.first, "Error: Untyped parameter.")
else
- prop.signature = new MMSignature(new Array[MMType], null, v.local_class.get_type)
+ prop.signature = new MMSignature(new Array[MMParam], null, v.local_class.get_type)
for clos in v.signature_builder.closure_decls do
prop.signature.closures.add(clos.variable.closure)
end
end
var prop = prop
- var signature = new MMSignature(new Array[MMType], t, v.local_class.get_type)
+ var signature = new MMSignature(new Array[MMParam], t, v.local_class.get_type)
prop.signature = signature
var visibility_level = n_visibility.level
process_and_check(v, prop, n_id != null and n_kwredef != null, visibility_level)
end
if n_writable != null or n_id == null then
var m = _writemethod.as(not null)
- m.signature = new MMSignature(new Array[MMType].with_items(t), null, v.local_class.get_type)
+ m.signature = new MMSignature(new Array[MMParam].with_items(new MMParam(t, once "value".to_symbol)), null, v.local_class.get_type)
var vl = visibility_level
if n_id == null then
if n_writable == null then vl = 3 else vl = n_writable.n_visibility.level # write accessor has a specific visibility
redef fun process_and_check(v, prop, has_redef, visibility_level)
do
prop.global.visibility_level = visibility_level
- prop.signature = new MMSignature(new Array[MMType], null, v.local_class.get_type)
+ prop.signature = new MMSignature(new Array[MMParam], null, v.local_class.get_type)
# Disable all checks for main
end
end
redef fun accept_property_verifier(v)
do
super
- var signature = new MMSignature(new Array[MMType], n_type.get_stype(v), v.local_class.get_type)
+ var signature = new MMSignature(new Array[MMParam], n_type.get_stype(v), v.local_class.get_type)
prop.signature = signature
var visibility_level = n_visibility.level
process_and_check(v, prop, n_kwredef != null, visibility_level)
end
redef class AMethid
- # Method name
- readable var _name: nullable Symbol
+ redef readable var _name: nullable Symbol
redef fun accept_property_builder(v)
do
return
end
else if not v.signature_builder.params.is_empty or n_type != null then
- var pars = new Array[MMType]
+ var pars = new Array[MMParam]
for p in v.signature_builder.params do
- pars.add(p.stype.as(not null))
+ pars.add( new MMParam( p.stype.as(not null), p.n_id.to_symbol ) )
end
var ret: nullable MMType = null
if n_type != null then
end
var sig = v.signature_builder.signature
if sig == null then
- sig = new MMSignature(new Array[MMType], null, v.local_class.get_type)
+ sig = new MMSignature(new Array[MMParam], null, v.local_class.get_type)
end
if sig.return_type != null and n_kwbreak != null then
v.error(self, "Syntax Error: A break block cannot have a return value.")
end
# Add the finalizer to the closure signature
- var finalize_sig = new MMSignature(new Array[MMType], null, v.mmmodule.type_any) # FIXME should be no receiver
+ var finalize_sig = new MMSignature(new Array[MMParam], null, v.mmmodule.type_any) # FIXME should be no receiver
var finalizer_clos = new MMClosure(once ("break".to_symbol), finalize_sig, false, true)
sig.closures.add(finalizer_clos)
# Automatic variables
readable writable var _variables: nullable Array[AutoVariable]
end
+
+redef class AMethid
+ # Name of method
+ fun name: nullable Symbol is abstract
+end
var raw_arity: Int
if raw_args == null then raw_arity = 0 else raw_arity = raw_args.length
if par_arity > raw_arity or (par_arity != raw_arity and par_vararg == -1) then
- v.error(self, "Error: arity missmatch; prototype is '{name}{psig}'.")
+ v.error(self, "Error: arity mismatch; prototype is '{name}{psig}'.")
return false
end
var arg_idx = 0
-alt/base_closure1_alt2.nit:25,3--7: Error: arity missmatch; prototype is 'bar'.
+alt/base_closure1_alt2.nit:25,3--7: Error: arity mismatch; prototype is 'bar'.
-alt/base_closure2_alt2.nit:25,3--5: Error: arity missmatch; prototype is 'bar(Int)'.
+alt/base_closure2_alt2.nit:25,3--5: Error: arity mismatch; prototype is 'bar(i: Int)'.
-alt/base_closure3_alt1.nit:25,3--14: Error: arity missmatch; prototype is 'bar(Int,Int,A)'.
+alt/base_closure3_alt1.nit:25,3--14: Error: arity mismatch; prototype is 'bar(k: Int, l: Int, a: A)'.
-alt/base_closure4_alt2.nit:25,3--7: Error: arity missmatch; prototype is 'bar: Int'.
+alt/base_closure4_alt2.nit:25,3--7: Error: arity mismatch; prototype is 'bar: Int'.
-alt/base_closure_break2_alt2.nit:26,17--21: Error: arity missmatch; prototype is 'bar'.
+alt/base_closure_break2_alt2.nit:26,17--21: Error: arity mismatch; prototype is 'bar'.
-alt/base_closure_break_alt2.nit:26,17--21: Error: arity missmatch; prototype is 'bar'.
+alt/base_closure_break_alt2.nit:26,17--21: Error: arity mismatch; prototype is 'bar'.
-alt/base_closure_raf_alt13.nit:27,3--8: Error: arity missmatch; prototype is 'bar'.
+alt/base_closure_raf_alt13.nit:27,3--8: Error: arity mismatch; prototype is 'bar'.
-alt/base_closure_raf_alt2.nit:29,3--5: Error: arity missmatch; prototype is 'bar(Int)'.
+alt/base_closure_raf_alt2.nit:29,3--5: Error: arity mismatch; prototype is 'bar(i: Int)'.
-alt/base_for_custom_alt3.nit:38,1--39,9: Error: Expected 1 variable (Int), found 2.
+alt/base_for_custom_alt3.nit:38,1--39,9: Error: Expected 1 variable (i: Int), found 2.
-alt/base_for_custom_alt4.nit:44,1--45,9: Error: Expected 2 variables (Int,Bool), found 1.
+alt/base_for_custom_alt4.nit:44,1--45,9: Error: Expected 2 variables (i: Int, j: Bool), found 1.
-alt/base_init_linext2_alt2.nit:99,2--5: Error: there is no available compatible constructor in B. Discarded candidates are base_init_linext2_alt2::B::initb, base_init_linext2_alt2::B::init_par, base_init_linext2_alt2::B::init_par2(Char).
+alt/base_init_linext2_alt2.nit:99,2--5: Error: there is no available compatible constructor in B. Discarded candidates are base_init_linext2_alt2::B::initb, base_init_linext2_alt2::B::init_par, base_init_linext2_alt2::B::init_par2(c: Char).
-alt/base_init_linext2_alt4.nit:99,2--5: Error: there is no available compatible constructor in B. Discarded candidates are base_init_linext2_alt4::B::initb, base_init_linext2_alt4::B::init_par, base_init_linext2_alt4::B::init_par2(Char).
+alt/base_init_linext2_alt4.nit:99,2--5: Error: there is no available compatible constructor in B. Discarded candidates are base_init_linext2_alt4::B::initb, base_init_linext2_alt4::B::init_par, base_init_linext2_alt4::B::init_par2(c: Char).
alt/base_init_linext2_alt4.nit:105,3--7: Error: Constructor of B must be invoked before constructor of C
-alt/base_vararg_alt1.nit:51,1--3: Error: arity missmatch; prototype is 'foo(Char)'.
+alt/base_vararg_alt1.nit:51,1--3: Error: arity mismatch; prototype is 'foo(a: Char)'.
-alt/base_vararg_alt2.nit:54,1--3: Error: arity missmatch; prototype is 'bar(Char,Char)'.
+alt/base_vararg_alt2.nit:54,1--3: Error: arity mismatch; prototype is 'bar(b: Char, a: Char)'.
-alt/base_vararg_alt3.nit:55,1--7: Error: arity missmatch; prototype is 'bar(Char,Char)'.
+alt/base_vararg_alt3.nit:55,1--7: Error: arity mismatch; prototype is 'bar(b: Char, a: Char)'.
-alt/base_vararg_alt4.nit:58,1--3: Error: arity missmatch; prototype is 'baz(Char,Char)'.
+alt/base_vararg_alt4.nit:58,1--3: Error: arity mismatch; prototype is 'baz(a: Char, b: Char)'.
-alt/base_vararg_alt5.nit:59,1--7: Error: arity missmatch; prototype is 'baz(Char,Char)'.
+alt/base_vararg_alt5.nit:59,1--7: Error: arity mismatch; prototype is 'baz(a: Char, b: Char)'.
-alt/base_vararg_alt6.nit:62,1--6: Error: arity missmatch; prototype is 'foobar(Char,Char,Char)'.
+alt/base_vararg_alt6.nit:62,1--6: Error: arity mismatch; prototype is 'foobar(b: Char, a: Char, c: Char)'.
-alt/base_vararg_alt7.nit:63,1--10: Error: arity missmatch; prototype is 'foobar(Char,Char,Char)'.
+alt/base_vararg_alt7.nit:63,1--10: Error: arity mismatch; prototype is 'foobar(b: Char, a: Char, c: Char)'.
-alt/base_vararg_alt8.nit:64,1--14: Error: arity missmatch; prototype is 'foobar(Char,Char,Char)'.
+alt/base_vararg_alt8.nit:64,1--14: Error: arity mismatch; prototype is 'foobar(b: Char, a: Char, c: Char)'.
alt/error_expr_not_ok_alt4.nit:45,7--10: Type error: expected A, got Object
alt/error_expr_not_ok_alt4.nit:46,1--9: Error: Method 'fail' doesn't exists in Object.
alt/error_expr_not_ok_alt4.nit:49,7--10: Type error: expected A, got Object
-alt/error_expr_not_ok_alt4.nit:50,1--10: Error: arity missmatch; prototype is 'trash(A)'.
+alt/error_expr_not_ok_alt4.nit:50,1--10: Error: arity mismatch; prototype is 'trash(x: A)'.
alt/error_expr_not_ok_alt4.nit:60,4--7: Type error: expected Bool, got Int
alt/error_expr_not_ok_alt4.nit:60,20: Type error: expected A, got Int
alt/error_expr_not_ok_alt4.nit:62,10--13: Type error: expected Bool, got Int
alt/error_expr_not_ok_alt5.nit:45,7--10: Type error: expected A, got Object
alt/error_expr_not_ok_alt5.nit:46,1--9: Error: Method 'fail' doesn't exists in Object.
alt/error_expr_not_ok_alt5.nit:49,7--10: Type error: expected A, got Object
-alt/error_expr_not_ok_alt5.nit:50,1--10: Error: arity missmatch; prototype is 'trash(A)'.
+alt/error_expr_not_ok_alt5.nit:50,1--10: Error: arity mismatch; prototype is 'trash(x: A)'.
alt/error_expr_not_ok_alt5.nit:60,4--7: Type error: expected Bool, got Int
alt/error_expr_not_ok_alt5.nit:60,20: Type error: expected A, got Int
alt/error_expr_not_ok_alt5.nit:62,10--13: Type error: expected Bool, got Int
-./error_init_auto.nit:34,5--9: Error: arity missmatch; prototype is 'init(Int)'.
-./error_init_auto.nit:36,5--14: Error: arity missmatch; prototype is 'init(Int)'.
-./error_init_auto.nit:37,5--17: Error: arity missmatch; prototype is 'init(Int)'.
+./error_init_auto.nit:34,5--9: Error: arity mismatch; prototype is 'init(recv: Int)'.
+./error_init_auto.nit:36,5--14: Error: arity mismatch; prototype is 'init(recv: Int)'.
+./error_init_auto.nit:37,5--17: Error: arity mismatch; prototype is 'init(recv: Int)'.
./error_init_auto.nit:38,5--15: Error: Method 'foo' doesn't exists in A.
-alt/error_init_auto_alt1.nit:34,5--11: Error: arity missmatch; prototype is 'init'.
-alt/error_init_auto_alt1.nit:35,5--14: Error: arity missmatch; prototype is 'init'.
-alt/error_init_auto_alt1.nit:36,5--17: Error: arity missmatch; prototype is 'init'.
+alt/error_init_auto_alt1.nit:34,5--11: Error: arity mismatch; prototype is 'init'.
+alt/error_init_auto_alt1.nit:35,5--14: Error: arity mismatch; prototype is 'init'.
+alt/error_init_auto_alt1.nit:36,5--17: Error: arity mismatch; prototype is 'init'.
alt/error_init_auto_alt1.nit:37,5--15: Error: Method 'foo' doesn't exists in A.
-alt/error_init_auto_alt2.nit:33,5--9: Error: arity missmatch; prototype is 'init(Int,Int)'.
-alt/error_init_auto_alt2.nit:34,5--11: Error: arity missmatch; prototype is 'init(Int,Int)'.
-alt/error_init_auto_alt2.nit:36,5--17: Error: arity missmatch; prototype is 'init(Int,Int)'.
+alt/error_init_auto_alt2.nit:33,5--9: Error: arity mismatch; prototype is 'init(recv: Int, recv: Int)'.
+alt/error_init_auto_alt2.nit:34,5--11: Error: arity mismatch; prototype is 'init(recv: Int, recv: Int)'.
+alt/error_init_auto_alt2.nit:36,5--17: Error: arity mismatch; prototype is 'init(recv: Int, recv: Int)'.
alt/error_init_auto_alt2.nit:37,5--15: Error: Method 'foo' doesn't exists in A.
-alt/error_init_auto_alt3.nit:34,5--9: Error: arity missmatch; prototype is 'init(Int)'.
-alt/error_init_auto_alt3.nit:36,5--14: Error: arity missmatch; prototype is 'init(Int)'.
-alt/error_init_auto_alt3.nit:37,5--17: Error: arity missmatch; prototype is 'init(Int)'.
+alt/error_init_auto_alt3.nit:34,5--9: Error: arity mismatch; prototype is 'init(xx: Int)'.
+alt/error_init_auto_alt3.nit:36,5--14: Error: arity mismatch; prototype is 'init(xx: Int)'.
+alt/error_init_auto_alt3.nit:37,5--17: Error: arity mismatch; prototype is 'init(xx: Int)'.
alt/error_init_auto_alt3.nit:38,5--15: Error: Method 'foo' doesn't exists in A.
../src/syntax/typing.nit:1274,74
'1' ... ../src/syntax/typing.nit:1274,74
../src/syntax/typing.nit:1275,4--1276,15
- ../src/syntax/typing.nit:1275,4--71
+ ../src/syntax/typing.nit:1275,4--70
../src/syntax/typing.nit:1275,4
../src/syntax/typing.nit:1275,4
'v' ... ../src/syntax/typing.nit:1275,4
'error' ... ../src/syntax/typing.nit:1275,6--10
../src/syntax/typing.nit:1275,12--15
'self' ... ../src/syntax/typing.nit:1275,12--15
- ../src/syntax/typing.nit:1275,18--71
- ../src/syntax/typing.nit:1275,18--57
- '"Error: arity missmatch; prototype is '{' ... ../src/syntax/typing.nit:1275,18--57
- ../src/syntax/typing.nit:1275,58--61
- ../src/syntax/typing.nit:1275,58
- 'name' ... ../src/syntax/typing.nit:1275,58--61
- ../src/syntax/typing.nit:1275,62--63
- '}{' ... ../src/syntax/typing.nit:1275,62--63
- ../src/syntax/typing.nit:1275,64--67
- ../src/syntax/typing.nit:1275,64
- 'psig' ... ../src/syntax/typing.nit:1275,64--67
- ../src/syntax/typing.nit:1275,68--71
- '}'."' ... ../src/syntax/typing.nit:1275,68--71
+ ../src/syntax/typing.nit:1275,18--70
+ ../src/syntax/typing.nit:1275,18--56
+ '"Error: arity mismatch; prototype is '{' ... ../src/syntax/typing.nit:1275,18--56
+ ../src/syntax/typing.nit:1275,57--60
+ ../src/syntax/typing.nit:1275,57
+ 'name' ... ../src/syntax/typing.nit:1275,57--60
+ ../src/syntax/typing.nit:1275,61--62
+ '}{' ... ../src/syntax/typing.nit:1275,61--62
+ ../src/syntax/typing.nit:1275,63--66
+ ../src/syntax/typing.nit:1275,63
+ 'psig' ... ../src/syntax/typing.nit:1275,63--66
+ ../src/syntax/typing.nit:1275,67--70
+ '}'."' ... ../src/syntax/typing.nit:1275,67--70
../src/syntax/typing.nit:1276,4--15
'return' ... ../src/syntax/typing.nit:1276,4--9
../src/syntax/typing.nit:1276,11--15
Read token at ../src/syntax/typing.nit:1275,11 text='('
Read token at ../src/syntax/typing.nit:1275,12--15 text='self'
Read token at ../src/syntax/typing.nit:1275,16 text=','
-Read token at ../src/syntax/typing.nit:1275,18--57 text='"Error: arity missmatch; prototype is '{'
-Read token at ../src/syntax/typing.nit:1275,58--61 text='name'
-Read token at ../src/syntax/typing.nit:1275,62--63 text='}{'
-Read token at ../src/syntax/typing.nit:1275,64--67 text='psig'
-Read token at ../src/syntax/typing.nit:1275,68--71 text='}'."'
-Read token at ../src/syntax/typing.nit:1275,72 text=')'
-Read token at ../src/syntax/typing.nit:1275,73--1276,0 text='
+Read token at ../src/syntax/typing.nit:1275,18--56 text='"Error: arity mismatch; prototype is '{'
+Read token at ../src/syntax/typing.nit:1275,57--60 text='name'
+Read token at ../src/syntax/typing.nit:1275,61--62 text='}{'
+Read token at ../src/syntax/typing.nit:1275,63--66 text='psig'
+Read token at ../src/syntax/typing.nit:1275,67--70 text='}'."'
+Read token at ../src/syntax/typing.nit:1275,71 text=')'
+Read token at ../src/syntax/typing.nit:1275,72--1276,0 text='
'
Read token at ../src/syntax/typing.nit:1276,4--9 text='return'
Read token at ../src/syntax/typing.nit:1276,11--15 text='false'