src: Update init
[nit.git] / src / nitni / nitni_callbacks.nit
index 8af9779..c9725d0 100644 (file)
@@ -111,7 +111,7 @@ redef class AMethPropdef
                # return type
                var rmt = mpropdef.msignature.return_mtype
                if rmt != null then
-                       if rmt isa MParameterType or rmt isa MVirtualType then
+                       if rmt isa MFormalType then
                                var mclass_type = mpropdef.mclassdef.bound_mtype
                                rmt = rmt.anchor_to(mmodule, mclass_type)
                        end
@@ -122,7 +122,7 @@ redef class AMethPropdef
                # params
                for p in mpropdef.msignature.mparameters do
                        var mtype = p.mtype.resolve_for(recv_type, recv_type, mmodule, true)
-                       if mtype isa MParameterType or mtype isa MVirtualType then
+                       if mtype isa MFormalType then
                                var mclass_type = mpropdef.mclassdef.bound_mtype
                                mtype = mtype.anchor_to(mmodule, mclass_type)
                        end
@@ -219,7 +219,7 @@ class MExplicitCall
 
                        var cname
                        if mproperty.is_init then
-                               if mproperty.name == "init" or mproperty.name == "new" then
+                               if mproperty.name == "init" or mproperty.name == "new" or mproperty.name == "defaultinit" then
                                        cname = "new_{recv_mtype.mangled_cname}"
                                else
                                        cname = "new_{recv_mtype.mangled_cname}_{mproperty.short_cname}"
@@ -287,7 +287,7 @@ redef class ALocalPropExternCall
                        mmodule, mclass_type, m_name )
 
                if method == null then
-                       toolcontext.error(location, "Local method {m_name} not found.")
+                       toolcontext.error(location, "Error: local method `{m_name}` not found.")
                        return
                end
 
@@ -304,16 +304,16 @@ redef class AFullPropExternCall
                var mmodule = npropdef.mpropdef.mclassdef.mmodule
                var mclassdef = npropdef.mpropdef.mclassdef
                var mclass_type = mclassdef.bound_mtype
-               var mtype = toolcontext.modelbuilder.resolve_mtype(mmodule, mclassdef, n_type)
+               var mtype = toolcontext.modelbuilder.resolve_mtype(mclassdef, n_type)
 
                if mtype == null then return
 
-               if mtype isa MParameterType or mtype isa MVirtualType then
+               if mtype isa MFormalType then
                        mtype = mtype.anchor_to(mmodule, mclass_type)
                end
 
                if mtype isa MNullableType then
-                       toolcontext.error(location, "Type {n_type.collect_text} is nullable and thus cannot be the receiver." )
+                       toolcontext.error(location, "Error: type `{n_type.collect_text}` is nullable and thus cannot be the receiver." )
                        return
                end
 
@@ -322,7 +322,7 @@ redef class AFullPropExternCall
                        mmodule, mtype, m_name )
 
                if method == null then
-                       toolcontext.error(location, "Method {m_name} not found in {n_type.collect_text}." )
+                       toolcontext.error(location, "Error: method `{m_name}` not found in `{n_type.collect_text}`." )
                        return
                end
 
@@ -337,20 +337,26 @@ redef class AInitPropExternCall
        do
                var mmodule = npropdef.mpropdef.mclassdef.mmodule
                var mclassdef = npropdef.mpropdef.mclassdef
-               var mtype = toolcontext.modelbuilder.resolve_mtype(mmodule, mclassdef, n_type)
+               var mtype = toolcontext.modelbuilder.resolve_mtype(mclassdef, n_type)
                if mtype == null then return
 
                if not mtype isa MClassType then
-                       toolcontext.error(location, "Type {n_type.collect_text} is not a class and thus cannot be used to instanciate a new instance." )
+                       toolcontext.error(location, "Error: type `{n_type.collect_text}` is not a class and thus cannot be used to instantiate a new instance." )
                        return
                end
 
-               var meth_name = "init"
+               var meth_name = "new"
                var meth = toolcontext.modelbuilder.try_get_mproperty_by_name2( self,
                        mmodule, mtype, meth_name )
 
                if meth == null then
-                       toolcontext.error(location, "Method {meth_name} not found in {n_type.collect_text}." )
+                       meth_name = "defaultinit"
+                       meth = toolcontext.modelbuilder.try_get_mproperty_by_name2( self,
+                               mmodule, mtype, meth_name )
+               end
+
+               if meth == null then
+                       toolcontext.error(location, "Error: method `{meth_name}` not found in `{n_type.collect_text}`." )
                        return
                end
 
@@ -392,9 +398,8 @@ redef class ACastAsExternCall
        redef fun verify_and_collect(npropdef, callback_set, toolcontext)
        do
                var mclassdef = npropdef.mpropdef.mclassdef
-               var mmodule = mclassdef.mmodule
-               toolcontext.modelbuilder.resolve_mtype_unchecked(mmodule, mclassdef, n_from_type, true)
-               toolcontext.modelbuilder.resolve_mtype_unchecked(mmodule, mclassdef, n_to_type, true)
+               toolcontext.modelbuilder.resolve_mtype_unchecked(mclassdef, n_from_type, true)
+               toolcontext.modelbuilder.resolve_mtype_unchecked(mclassdef, n_to_type, true)
                super
        end
 end
@@ -406,8 +411,7 @@ redef class AAsNullableExternCall
        redef fun verify_and_collect(npropdef, callback_set, toolcontext)
        do
                var mclassdef = npropdef.mpropdef.mclassdef
-               var mmodule = mclassdef.mmodule
-               toolcontext.modelbuilder.resolve_mtype_unchecked(mmodule, mclassdef, n_type, true)
+               toolcontext.modelbuilder.resolve_mtype_unchecked(mclassdef, n_type, true)
                super
        end
 end
@@ -416,15 +420,14 @@ redef class AAsNotNullableExternCall
        redef fun from_mtype do return n_type.mtype.as_nullable
        redef fun to_mtype do
                var mtype = n_type.mtype.as(not null)
-               mtype = mtype.as_notnullable
+               mtype = mtype.undecorate
                return mtype
        end
 
        redef fun verify_and_collect(npropdef, callback_set, toolcontext)
        do
                var mclassdef = npropdef.mpropdef.mclassdef
-               var mmodule = mclassdef.mmodule
-               toolcontext.modelbuilder.resolve_mtype_unchecked(mmodule, mclassdef, n_type, true)
+               toolcontext.modelbuilder.resolve_mtype_unchecked(mclassdef, n_type, true)
                super
        end
 end