modelize: make `mclassdef2nclassdef` and `mpropdef2npropdef` private
[nit.git] / src / modelize / modelize_property.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2012 Jean Privat <jean@pryen.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Analysis and verification of property definitions to instantiate model element
18 module modelize_property
19
20 intrude import modelize_class
21 private import annotation
22
23 redef class ToolContext
24 var modelize_property_phase: Phase = new ModelizePropertyPhase(self, [modelize_class_phase])
25 end
26
27 private class ModelizePropertyPhase
28 super Phase
29 redef fun process_nmodule(nmodule)
30 do
31 for nclassdef in nmodule.n_classdefs do
32 if nclassdef.all_defs == null then continue # skip non principal classdef
33 toolcontext.modelbuilder.build_properties(nclassdef)
34 end
35 end
36 end
37
38 redef class ModelBuilder
39 # Registration of the npropdef associated to each mpropdef.
40 #
41 # Public clients need to use `mpropdef2node` to access stuff.
42 private var mpropdef2npropdef = new HashMap[MPropDef, APropdef]
43
44 # Retrieve the associated AST node of a mpropertydef.
45 # This method is used to associate model entity with syntactic entities.
46 #
47 # If the property definition is not associated with a node, returns node.
48 fun mpropdef2node(mpropdef: MPropDef): nullable ANode
49 do
50 var res: nullable ANode = mpropdef2npropdef.get_or_null(mpropdef)
51 if res != null then return res
52 if mpropdef isa MMethodDef and mpropdef.mproperty.is_root_init then
53 res = mclassdef2nclassdef.get_or_null(mpropdef.mclassdef)
54 if res != null then return res
55 end
56 return null
57 end
58
59 # Retrieve all the attributes nodes localy definied
60 # FIXME think more about this method and how the separations separate/global and ast/model should be done.
61 fun collect_attr_propdef(mclassdef: MClassDef): Array[AAttrPropdef]
62 do
63 var res = new Array[AAttrPropdef]
64 var n = mclassdef2nclassdef.get_or_null(mclassdef)
65 if n == null then return res
66 for npropdef in n.n_propdefs do
67 if npropdef isa AAttrPropdef then
68 res.add(npropdef)
69 end
70 end
71 return res
72 end
73
74 # Build the properties of `nclassdef`.
75 # REQUIRE: all superclasses are built.
76 private fun build_properties(nclassdef: AClassdef)
77 do
78 # Force building recursively
79 if nclassdef.build_properties_is_done then return
80 nclassdef.build_properties_is_done = true
81 var mclassdef = nclassdef.mclassdef.as(not null)
82 if mclassdef.in_hierarchy == null then return # Skip error
83 for superclassdef in mclassdef.in_hierarchy.direct_greaters do
84 if not mclassdef2nclassdef.has_key(superclassdef) then continue
85 build_properties(mclassdef2nclassdef[superclassdef])
86 end
87
88 mclassdef.build_self_type(self, nclassdef)
89 for nclassdef2 in nclassdef.all_defs do
90 for npropdef in nclassdef2.n_propdefs do
91 npropdef.build_property(self, mclassdef)
92 end
93 for npropdef in nclassdef2.n_propdefs do
94 npropdef.build_signature(self)
95 end
96 for npropdef in nclassdef2.n_propdefs do
97 npropdef.check_signature(self)
98 end
99 end
100 process_default_constructors(nclassdef)
101 end
102
103 # the root init of the Object class
104 # Is usually implicitly defined
105 # Then explicit or implicit definitions of root-init are attached to it
106 var the_root_init_mmethod: nullable MMethod
107
108 # Introduce or inherit default constructor
109 # This is the last part of `build_properties`.
110 private fun process_default_constructors(nclassdef: AClassdef)
111 do
112 var mclassdef = nclassdef.mclassdef.as(not null)
113
114 # Are we a refinement
115 if not mclassdef.is_intro then return
116
117 # Look for the init in Object, or create it
118 if mclassdef.mclass.name == "Object" and the_root_init_mmethod == null then
119 # Create the implicit root-init method
120 var mprop = new MMethod(mclassdef, "init", mclassdef.mclass.visibility)
121 mprop.is_root_init = true
122 var mpropdef = new MMethodDef(mclassdef, mprop, nclassdef.location)
123 var mparameters = new Array[MParameter]
124 var msignature = new MSignature(mparameters, null)
125 mpropdef.msignature = msignature
126 mpropdef.new_msignature = msignature
127 mprop.is_init = true
128 nclassdef.mfree_init = mpropdef
129 self.toolcontext.info("{mclassdef} gets a free empty constructor {mpropdef}{msignature}", 3)
130 the_root_init_mmethod = mprop
131 return
132 end
133
134 # Is the class forbid constructors?
135 if not mclassdef.mclass.kind.need_init then return
136
137 # Is there already a constructor defined?
138 var defined_init: nullable MMethodDef = null
139 for mpropdef in mclassdef.mpropdefs do
140 if not mpropdef isa MMethodDef then continue
141 if not mpropdef.mproperty.is_init then continue
142 if mpropdef.mproperty.is_root_init then
143 assert defined_init == null
144 defined_init = mpropdef
145 else if mpropdef.mproperty.name == "init" then
146 # An explicit old-style init named "init", so return
147 return
148 end
149 end
150
151 if not nclassdef isa AStdClassdef then return
152
153 # Collect undefined attributes
154 var mparameters = new Array[MParameter]
155 var initializers = new Array[MProperty]
156 for npropdef in nclassdef.n_propdefs do
157 if npropdef isa AMethPropdef then
158 if npropdef.mpropdef == null then return # Skip broken attribute
159 var at = npropdef.get_single_annotation("autoinit", self)
160 if at == null then continue # Skip non tagged init
161
162 var sig = npropdef.mpropdef.msignature
163 if sig == null then continue # Skip broken method
164
165 if not npropdef.mpropdef.is_intro then
166 self.error(at, "Error: `autoinit` cannot be set on redefinitions")
167 continue
168 end
169
170 for param in sig.mparameters do
171 var ret_type = param.mtype
172 var mparameter = new MParameter(param.name, ret_type, false)
173 mparameters.add(mparameter)
174 end
175 initializers.add(npropdef.mpropdef.mproperty)
176 end
177 if npropdef isa AAttrPropdef then
178 if npropdef.mpropdef == null then return # Skip broken attribute
179 if npropdef.noinit then continue # Skip noinit attribute
180 var atautoinit = npropdef.get_single_annotation("autoinit", self)
181 if atautoinit != null then
182 # For autoinit attributes, call the reader to force
183 # the lazy initialization of the attribute.
184 initializers.add(npropdef.mreadpropdef.mproperty)
185 continue
186 end
187 if npropdef.has_value then continue
188 var paramname = npropdef.mpropdef.mproperty.name.substring_from(1)
189 var ret_type = npropdef.mpropdef.static_mtype
190 if ret_type == null then return
191 var mparameter = new MParameter(paramname, ret_type, false)
192 mparameters.add(mparameter)
193 var msetter = npropdef.mwritepropdef
194 if msetter == null then
195 # No setter, it is a old-style attribute, so just add it
196 initializers.add(npropdef.mpropdef.mproperty)
197 else
198 # Add the setter to the list
199 initializers.add(msetter.mproperty)
200 end
201 end
202 end
203
204 if the_root_init_mmethod == null then return
205
206 # Look for most-specific new-stype init definitions
207 var spropdefs = the_root_init_mmethod.lookup_super_definitions(mclassdef.mmodule, mclassdef.bound_mtype)
208 if spropdefs.is_empty then
209 toolcontext.error(nclassdef.location, "Error: {mclassdef} does not specialize {the_root_init_mmethod.intro_mclassdef}. Possible duplication of the root class `Object`?")
210 return
211 end
212
213 # Search the longest-one and checks for conflict
214 var longest = spropdefs.first
215 if spropdefs.length > 1 then
216 # Check for conflict in the order of initializers
217 # Each initializer list must me a prefix of the longest list
218 # part 1. find the longest list
219 for spd in spropdefs do
220 if spd.initializers.length > longest.initializers.length then longest = spd
221 end
222 # part 2. compare
223 for spd in spropdefs do
224 var i = 0
225 for p in spd.initializers do
226 if p != longest.initializers[i] then
227 self.error(nclassdef, "Error: conflict for inherited inits {spd}({spd.initializers.join(", ")}) and {longest}({longest.initializers.join(", ")})")
228 return
229 end
230 i += 1
231 end
232 end
233 end
234
235 # Can we just inherit?
236 if spropdefs.length == 1 and mparameters.is_empty and defined_init == null then
237 self.toolcontext.info("{mclassdef} inherits the basic constructor {longest}", 3)
238 mclassdef.mclass.root_init = longest
239 return
240 end
241
242 # Combine the inherited list to what is collected
243 if longest.initializers.length > 0 then
244 mparameters.prepend longest.new_msignature.mparameters
245 initializers.prepend longest.initializers
246 end
247
248 # If we already have a basic init definition, then setup its initializers
249 if defined_init != null then
250 defined_init.initializers.add_all(initializers)
251 var msignature = new MSignature(mparameters, null)
252 defined_init.new_msignature = msignature
253 self.toolcontext.info("{mclassdef} extends its basic constructor signature to {defined_init}{msignature}", 3)
254 mclassdef.mclass.root_init = defined_init
255 return
256 end
257
258 # Else create the local implicit basic init definition
259 var mprop = the_root_init_mmethod.as(not null)
260 var mpropdef = new MMethodDef(mclassdef, mprop, nclassdef.location)
261 mpropdef.has_supercall = true
262 mpropdef.initializers.add_all(initializers)
263 var msignature = new MSignature(mparameters, null)
264 mpropdef.new_msignature = msignature
265 mpropdef.msignature = new MSignature(new Array[MParameter], null) # always an empty real signature
266 nclassdef.mfree_init = mpropdef
267 self.toolcontext.info("{mclassdef} gets a free constructor for attributes {mpropdef}{msignature}", 3)
268 mclassdef.mclass.root_init = mpropdef
269 end
270
271 # Check the visibility of `mtype` as an element of the signature of `mpropdef`.
272 fun check_visibility(node: ANode, mtype: MType, mpropdef: MPropDef)
273 do
274 var mmodule = mpropdef.mclassdef.mmodule
275 var mproperty = mpropdef.mproperty
276
277 # Extract visibility information of the main part of `mtype`
278 # It is a case-by case
279 var vis_type: nullable MVisibility = null # The own visibility of the type
280 var mmodule_type: nullable MModule = null # The original module of the type
281 mtype = mtype.as_notnullable
282 if mtype isa MClassType then
283 vis_type = mtype.mclass.visibility
284 mmodule_type = mtype.mclass.intro.mmodule
285 else if mtype isa MVirtualType then
286 vis_type = mtype.mproperty.visibility
287 mmodule_type = mtype.mproperty.intro_mclassdef.mmodule
288 else if mtype isa MParameterType then
289 # nothing, always visible
290 else
291 node.debug "Unexpected type {mtype}"
292 abort
293 end
294
295 if vis_type != null then
296 assert mmodule_type != null
297 var vis_module_type = mmodule.visibility_for(mmodule_type) # the visibility of the original module
298 if mproperty.visibility > vis_type then
299 error(node, "Error: The {mproperty.visibility} property `{mproperty}` cannot contain the {vis_type} type `{mtype}`")
300 return
301 else if mproperty.visibility > vis_module_type then
302 error(node, "Error: The {mproperty.visibility} property `{mproperty}` cannot contain the type `{mtype}` from the {vis_module_type} module `{mmodule_type}`")
303 return
304 end
305 end
306
307 # No error, try to go deeper in generic types
308 if node isa AType then
309 for a in node.n_types do
310 var t = a.mtype
311 if t == null then continue # Error, thus skipped
312 check_visibility(a, t, mpropdef)
313 end
314 else if mtype isa MGenericType then
315 for t in mtype.arguments do check_visibility(node, t, mpropdef)
316 end
317 end
318 end
319
320 redef class MPropDef
321 # Does the MPropDef contains a call to super or a call of a super-constructor?
322 # Subsequent phases of the frontend (esp. typing) set it if required
323 var has_supercall: Bool = false is writable
324 end
325
326 redef class AClassdef
327 var build_properties_is_done = false
328
329 # The free init (implicitely constructed by the class if required)
330 var mfree_init: nullable MMethodDef = null
331 end
332
333 redef class MClass
334 # The base init of the class.
335 # Used to get the common new_msignature and initializers
336 #
337 # TODO: Where to put this information is not clear because unlike other
338 # informations, the initialisers are stable in a same class.
339 var root_init: nullable MMethodDef = null
340 end
341
342 redef class MClassDef
343 # What is the `APropdef` associated to a `MProperty`?
344 # Used to check multiple definition of a property.
345 var mprop2npropdef: Map[MProperty, APropdef] = new HashMap[MProperty, APropdef]
346
347 # Build the virtual type `SELF` only for introduction `MClassDef`
348 fun build_self_type(modelbuilder: ModelBuilder, nclassdef: AClassdef)
349 do
350 if not is_intro then return
351
352 var name = "SELF"
353 var mprop = modelbuilder.try_get_mproperty_by_name(nclassdef, self, name)
354
355 # If SELF type is declared nowherer?
356 if mprop == null then return
357
358 # SELF is not a virtual type? it is weird but we ignore it
359 if not mprop isa MVirtualTypeProp then return
360
361 # Is this the intro of SELF in the library?
362 var intro = mprop.intro
363 var intro_mclassdef = intro.mclassdef
364 if intro_mclassdef == self then
365 var nintro = modelbuilder.mpropdef2npropdef[intro]
366
367 # SELF must be declared in Object, otherwise this will create conflicts
368 if intro_mclassdef.mclass.name != "Object" then
369 modelbuilder.error(nintro, "Error: the virtual type SELF must be declared in Object.")
370 end
371
372 # SELF must be public
373 if mprop.visibility != public_visibility then
374 modelbuilder.error(nintro, "Error: the virtual type SELF must be public.")
375 end
376
377 # SELF must not be fixed
378 if intro.is_fixed then
379 modelbuilder.error(nintro, "Error: the virtual type SELF cannot be fixed.")
380 end
381
382 return
383 end
384
385 # This class introduction inherits a SELF
386 # We insert an artificial property to update it
387 var mpropdef = new MVirtualTypeDef(self, mprop, self.location)
388 mpropdef.bound = mclass.mclass_type
389 end
390 end
391
392 redef class APropdef
393 # The associated main model entity
394 type MPROPDEF: MPropDef
395
396 # The associated propdef once build by a `ModelBuilder`
397 var mpropdef: nullable MPROPDEF is writable
398
399 private fun build_property(modelbuilder: ModelBuilder, mclassdef: MClassDef) is abstract
400 private fun build_signature(modelbuilder: ModelBuilder) is abstract
401 private fun check_signature(modelbuilder: ModelBuilder) is abstract
402 private fun new_property_visibility(modelbuilder: ModelBuilder, mclassdef: MClassDef, nvisibility: nullable AVisibility): MVisibility
403 do
404 var mvisibility = public_visibility
405 if nvisibility != null then
406 mvisibility = nvisibility.mvisibility
407 if mvisibility == intrude_visibility then
408 modelbuilder.error(nvisibility, "Error: intrude is not a legal visibility for properties.")
409 mvisibility = public_visibility
410 end
411 end
412 if mclassdef.mclass.visibility == private_visibility then
413 if mvisibility == protected_visibility then
414 assert nvisibility != null
415 modelbuilder.error(nvisibility, "Error: The only legal visibility for properties in a private class is private.")
416 else if mvisibility == private_visibility then
417 assert nvisibility != null
418 modelbuilder.advice(nvisibility, "useless-visibility", "Warning: private is superfluous since the only legal visibility for properties in a private class is private.")
419 end
420 mvisibility = private_visibility
421 end
422 return mvisibility
423 end
424
425 private fun set_doc(mpropdef: MPropDef, modelbuilder: ModelBuilder)
426 do
427 var ndoc = self.n_doc
428 if ndoc != null then
429 var mdoc = ndoc.to_mdoc
430 mpropdef.mdoc = mdoc
431 mdoc.original_mentity = mpropdef
432 else if mpropdef.is_intro and mpropdef.mproperty.visibility >= protected_visibility then
433 modelbuilder.advice(self, "missing-doc", "Documentation warning: Undocumented property `{mpropdef.mproperty}`")
434 end
435
436 var at_deprecated = get_single_annotation("deprecated", modelbuilder)
437 if at_deprecated != null then
438 if not mpropdef.is_intro then
439 modelbuilder.error(self, "Error: method redefinition cannot be deprecated.")
440 else
441 var info = new MDeprecationInfo
442 ndoc = at_deprecated.n_doc
443 if ndoc != null then info.mdoc = ndoc.to_mdoc
444 mpropdef.mproperty.deprecation = info
445 end
446 end
447 end
448
449 private fun check_redef_property_visibility(modelbuilder: ModelBuilder, nvisibility: nullable AVisibility, mprop: MProperty)
450 do
451 if nvisibility == null then return
452 var mvisibility = nvisibility.mvisibility
453 if mvisibility != mprop.visibility and mvisibility != public_visibility then
454 modelbuilder.error(nvisibility, "Error: redefinition changed the visibility from a {mprop.visibility} to a {mvisibility}")
455 end
456 end
457
458 private fun check_redef_keyword(modelbuilder: ModelBuilder, mclassdef: MClassDef, kwredef: nullable Token, need_redef: Bool, mprop: MProperty): Bool
459 do
460 if mclassdef.mprop2npropdef.has_key(mprop) then
461 modelbuilder.error(self, "Error: A property {mprop} is already defined in class {mclassdef.mclass} at line {mclassdef.mprop2npropdef[mprop].location.line_start}.")
462 return false
463 end
464 if mprop isa MMethod and mprop.is_toplevel != (parent isa ATopClassdef) then
465 if mprop.is_toplevel then
466 modelbuilder.error(self, "Error: {mprop} is a top level method.")
467 else
468 modelbuilder.error(self, "Error: {mprop} is not a top level method.")
469 end
470 return false
471
472 end
473 if kwredef == null then
474 if need_redef then
475 modelbuilder.error(self, "Redef error: {mclassdef.mclass}::{mprop.name} is an inherited property. To redefine it, add the redef keyword.")
476 return false
477 end
478 else
479 if not need_redef then
480 modelbuilder.error(self, "Error: No property {mclassdef.mclass}::{mprop.name} is inherited. Remove the redef keyword to define a new property.")
481 return false
482 end
483 end
484 return true
485 end
486
487 end
488
489 redef class ASignature
490 # Is the model builder has correctly visited the signature
491 var is_visited = false
492 # Names of parameters from the AST
493 # REQUIRE: is_visited
494 var param_names = new Array[String]
495 # Types of parameters from the AST
496 # REQUIRE: is_visited
497 var param_types = new Array[MType]
498 # Rank of the vararg (of -1 if none)
499 # REQUIRE: is_visited
500 var vararg_rank: Int = -1
501 # Return type
502 var ret_type: nullable MType = null
503
504 # Visit and fill information about a signature
505 private fun visit_signature(modelbuilder: ModelBuilder, mclassdef: MClassDef): Bool
506 do
507 var mmodule = mclassdef.mmodule
508 var param_names = self.param_names
509 var param_types = self.param_types
510 for np in self.n_params do
511 param_names.add(np.n_id.text)
512 var ntype = np.n_type
513 if ntype != null then
514 var mtype = modelbuilder.resolve_mtype(mmodule, mclassdef, ntype)
515 if mtype == null then return false # Skip error
516 for i in [0..param_names.length-param_types.length[ do
517 param_types.add(mtype)
518 end
519 if np.n_dotdotdot != null then
520 if self.vararg_rank != -1 then
521 modelbuilder.error(np, "Error: {param_names[self.vararg_rank]} is already a vararg")
522 return false
523 else
524 self.vararg_rank = param_names.length - 1
525 end
526 end
527 end
528 end
529 var ntype = self.n_type
530 if ntype != null then
531 self.ret_type = modelbuilder.resolve_mtype(mmodule, mclassdef, ntype)
532 if self.ret_type == null then return false # Skip error
533 end
534
535 self.is_visited = true
536 return true
537 end
538
539 # Build a visited signature
540 fun build_signature(modelbuilder: ModelBuilder): nullable MSignature
541 do
542 if param_names.length != param_types.length then
543 # Some parameters are typed, other parameters are not typed.
544 modelbuilder.error(self.n_params[param_types.length], "Error: Untyped parameter `{param_names[param_types.length]}'.")
545 return null
546 end
547
548 var mparameters = new Array[MParameter]
549 for i in [0..param_names.length[ do
550 var mparameter = new MParameter(param_names[i], param_types[i], i == vararg_rank)
551 self.n_params[i].mparameter = mparameter
552 mparameters.add(mparameter)
553 end
554
555 var msignature = new MSignature(mparameters, ret_type)
556 return msignature
557 end
558 end
559
560 redef class AParam
561 # The associated mparameter if any
562 var mparameter: nullable MParameter = null
563 end
564
565 redef class AMethPropdef
566 redef type MPROPDEF: MMethodDef
567
568
569 # Can self be used as a root init?
570 private fun look_like_a_root_init(modelbuilder: ModelBuilder, mclassdef: MClassDef): Bool
571 do
572 # Need the `init` keyword
573 if n_kwinit == null then return false
574 # Need to by anonymous
575 if self.n_methid != null then return false
576 # No annotation on itself
577 if get_single_annotation("old_style_init", modelbuilder) != null then return false
578 # Nor on its module
579 var amod = self.parent.parent.as(AModule)
580 var amoddecl = amod.n_moduledecl
581 if amoddecl != null then
582 var old = amoddecl.get_single_annotation("old_style_init", modelbuilder)
583 if old != null then return false
584 end
585 # No parameters
586 if self.n_signature.n_params.length > 0 then
587 modelbuilder.advice(self, "old-init", "Warning: init with signature in {mclassdef}")
588 return false
589 end
590 # Cannot be private or something
591 if not self.n_visibility isa APublicVisibility then
592 modelbuilder.advice(self, "old-init", "Warning: non-public init in {mclassdef}")
593 return false
594 end
595
596 return true
597 end
598
599 redef fun build_property(modelbuilder, mclassdef)
600 do
601 var n_kwinit = n_kwinit
602 var n_kwnew = n_kwnew
603 var is_init = n_kwinit != null or n_kwnew != null
604 var name: String
605 var amethodid = self.n_methid
606 var name_node: ANode
607 if amethodid == null then
608 if not is_init then
609 name = "main"
610 name_node = self
611 else if n_kwinit != null then
612 name = "init"
613 name_node = n_kwinit
614 else if n_kwnew != null then
615 name = "new"
616 name_node = n_kwnew
617 else
618 abort
619 end
620 else if amethodid isa AIdMethid then
621 name = amethodid.n_id.text
622 name_node = amethodid
623 else
624 # operator, bracket or assign
625 name = amethodid.collect_text
626 name_node = amethodid
627
628 if name == "-" and self.n_signature.n_params.length == 0 then
629 name = "unary -"
630 end
631 end
632
633 var look_like_a_root_init = look_like_a_root_init(modelbuilder, mclassdef)
634 var mprop: nullable MMethod = null
635 if not is_init or n_kwredef != null then mprop = modelbuilder.try_get_mproperty_by_name(name_node, mclassdef, name).as(nullable MMethod)
636 if mprop == null and look_like_a_root_init then
637 mprop = modelbuilder.the_root_init_mmethod
638 var nb = n_block
639 if nb isa ABlockExpr and nb.n_expr.is_empty and n_doc == null then
640 modelbuilder.advice(self, "useless-init", "Warning: useless empty init in {mclassdef}")
641 end
642 end
643 if mprop == null then
644 var mvisibility = new_property_visibility(modelbuilder, mclassdef, self.n_visibility)
645 mprop = new MMethod(mclassdef, name, mvisibility)
646 if look_like_a_root_init and modelbuilder.the_root_init_mmethod == null then
647 modelbuilder.the_root_init_mmethod = mprop
648 mprop.is_root_init = true
649 end
650 mprop.is_init = is_init
651 mprop.is_new = n_kwnew != null
652 if parent isa ATopClassdef then mprop.is_toplevel = true
653 self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, false, mprop)
654 else
655 if not mprop.is_root_init and not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, not self isa AMainMethPropdef, mprop) then return
656 check_redef_property_visibility(modelbuilder, self.n_visibility, mprop)
657 end
658 mclassdef.mprop2npropdef[mprop] = self
659
660 var mpropdef = new MMethodDef(mclassdef, mprop, self.location)
661
662 set_doc(mpropdef, modelbuilder)
663
664 self.mpropdef = mpropdef
665 modelbuilder.mpropdef2npropdef[mpropdef] = self
666 if mpropdef.is_intro then
667 modelbuilder.toolcontext.info("{mpropdef} introduces new method {mprop.full_name}", 4)
668 else
669 modelbuilder.toolcontext.info("{mpropdef} redefines method {mprop.full_name}", 4)
670 end
671 end
672
673 redef fun build_signature(modelbuilder)
674 do
675 var mpropdef = self.mpropdef
676 if mpropdef == null then return # Error thus skiped
677 var mclassdef = mpropdef.mclassdef
678 var mmodule = mclassdef.mmodule
679 var nsig = self.n_signature
680
681 if mpropdef.mproperty.is_root_init and not mclassdef.is_intro then
682 var root_init = mclassdef.mclass.root_init
683 if root_init != null then
684 # Inherit the initializers by refinement
685 mpropdef.new_msignature = root_init.new_msignature
686 assert mpropdef.initializers.is_empty
687 mpropdef.initializers.add_all root_init.initializers
688 end
689 end
690
691 # Retrieve info from the signature AST
692 var param_names = new Array[String] # Names of parameters from the AST
693 var param_types = new Array[MType] # Types of parameters from the AST
694 var vararg_rank = -1
695 var ret_type: nullable MType = null # Return type from the AST
696 if nsig != null then
697 if not nsig.visit_signature(modelbuilder, mclassdef) then return
698 param_names = nsig.param_names
699 param_types = nsig.param_types
700 vararg_rank = nsig.vararg_rank
701 ret_type = nsig.ret_type
702 end
703
704 # Look for some signature to inherit
705 # FIXME: do not inherit from the intro, but from the most specific
706 var msignature: nullable MSignature = null
707 if not mpropdef.is_intro then
708 msignature = mpropdef.mproperty.intro.msignature
709 if msignature == null then return # Skip error
710
711 # Check inherited signature arity
712 if param_names.length != msignature.arity then
713 var node: ANode
714 if nsig != null then node = nsig else node = self
715 modelbuilder.error(node, "Redef error: {mpropdef} redefines {mpropdef.mproperty.intro} with {param_names.length} parameter(s), {msignature.arity} expected. Signature is {mpropdef}{msignature}")
716 return
717 end
718 else if mpropdef.mproperty.is_init and not mpropdef.mproperty.is_new then
719 # FIXME UGLY: inherit signature from a super-constructor
720 for msupertype in mclassdef.supertypes do
721 msupertype = msupertype.anchor_to(mmodule, mclassdef.bound_mtype)
722 var candidate = modelbuilder.try_get_mproperty_by_name2(self, mmodule, msupertype, mpropdef.mproperty.name)
723 if candidate != null then
724 if msignature == null then
725 msignature = candidate.intro.as(MMethodDef).msignature
726 end
727 end
728 end
729 end
730
731
732 # Inherit the signature
733 if msignature != null and param_names.length != param_types.length and param_names.length == msignature.arity and param_types.length == 0 then
734 # Parameters are untyped, thus inherit them
735 param_types = new Array[MType]
736 for mparameter in msignature.mparameters do
737 param_types.add(mparameter.mtype)
738 end
739 vararg_rank = msignature.vararg_rank
740 end
741 if msignature != null and ret_type == null then
742 ret_type = msignature.return_mtype
743 end
744
745 if param_names.length != param_types.length then
746 # Some parameters are typed, other parameters are not typed.
747 modelbuilder.error(nsig.n_params[param_types.length], "Error: Untyped parameter `{param_names[param_types.length]}'.")
748 return
749 end
750
751 var mparameters = new Array[MParameter]
752 for i in [0..param_names.length[ do
753 var mparameter = new MParameter(param_names[i], param_types[i], i == vararg_rank)
754 if nsig != null then nsig.n_params[i].mparameter = mparameter
755 mparameters.add(mparameter)
756 end
757
758 # In `new`-factories, the return type is by default the classtype.
759 if ret_type == null and mpropdef.mproperty.is_new then ret_type = mclassdef.mclass.mclass_type
760
761 msignature = new MSignature(mparameters, ret_type)
762 mpropdef.msignature = msignature
763 mpropdef.is_abstract = self.get_single_annotation("abstract", modelbuilder) != null
764 mpropdef.is_intern = self.get_single_annotation("intern", modelbuilder) != null
765 mpropdef.is_extern = self.n_extern_code_block != null or self.get_single_annotation("extern", modelbuilder) != null
766 end
767
768 redef fun check_signature(modelbuilder)
769 do
770 var mpropdef = self.mpropdef
771 if mpropdef == null then return # Error thus skiped
772 var mclassdef = mpropdef.mclassdef
773 var mmodule = mclassdef.mmodule
774 var nsig = self.n_signature
775 var mysignature = self.mpropdef.msignature
776 if mysignature == null then return # Error thus skiped
777
778 # Lookup for signature in the precursor
779 # FIXME all precursors should be considered
780 if not mpropdef.is_intro then
781 var msignature = mpropdef.mproperty.intro.msignature
782 if msignature == null then return
783
784 var precursor_ret_type = msignature.return_mtype
785 var ret_type = mysignature.return_mtype
786 if ret_type != null and precursor_ret_type == null then
787 modelbuilder.error(nsig.n_type.as(not null), "Redef Error: {mpropdef.mproperty} is a procedure, not a function.")
788 return
789 end
790
791 if mysignature.arity > 0 then
792 # Check parameters types
793 for i in [0..mysignature.arity[ do
794 var myt = mysignature.mparameters[i].mtype
795 var prt = msignature.mparameters[i].mtype
796 if not myt.is_subtype(mmodule, mclassdef.bound_mtype, prt) or
797 not prt.is_subtype(mmodule, mclassdef.bound_mtype, myt) then
798 modelbuilder.error(nsig.n_params[i], "Redef Error: Wrong type for parameter `{mysignature.mparameters[i].name}'. found {myt}, expected {prt} as in {mpropdef.mproperty.intro}.")
799 end
800 end
801 end
802 if precursor_ret_type != null then
803 if ret_type == null then
804 # Inherit the return type
805 ret_type = precursor_ret_type
806 else if not ret_type.is_subtype(mmodule, mclassdef.bound_mtype, precursor_ret_type) then
807 modelbuilder.error(nsig.n_type.as(not null), "Redef Error: Wrong return type. found {ret_type}, expected {precursor_ret_type} as in {mpropdef.mproperty.intro}.")
808 end
809 end
810 end
811
812 if mysignature.arity > 0 then
813 # Check parameters visibility
814 for i in [0..mysignature.arity[ do
815 var nt = nsig.n_params[i].n_type
816 if nt != null then modelbuilder.check_visibility(nt, nt.mtype.as(not null), mpropdef)
817 end
818 var nt = nsig.n_type
819 if nt != null then modelbuilder.check_visibility(nt, nt.mtype.as(not null), mpropdef)
820 end
821 end
822 end
823
824 redef class AAttrPropdef
825 redef type MPROPDEF: MAttributeDef
826
827 # Is the node tagged `noinit`?
828 var noinit = false
829
830 # Is the node tagged lazy?
831 var is_lazy = false
832
833 # Has the node a default value?
834 # Could be through `n_expr` or `n_block`
835 var has_value = false
836
837 # The guard associated to a lazy attribute.
838 # Because some engines does not have a working `isset`,
839 # this additional attribute is used to guard the lazy initialization.
840 # TODO: to remove once isset is correctly implemented
841 var mlazypropdef: nullable MAttributeDef
842
843 # The associated getter (read accessor) if any
844 var mreadpropdef: nullable MMethodDef is writable
845 # The associated setter (write accessor) if any
846 var mwritepropdef: nullable MMethodDef is writable
847
848 redef fun build_property(modelbuilder, mclassdef)
849 do
850 var mclass = mclassdef.mclass
851
852 var name: String
853 name = self.n_id2.text
854
855 if mclass.kind == interface_kind or mclassdef.mclass.kind == enum_kind then
856 modelbuilder.error(self, "Error: Attempt to define attribute {name} in the interface {mclass}.")
857 else if mclass.kind == enum_kind then
858 modelbuilder.error(self, "Error: Attempt to define attribute {name} in the enum class {mclass}.")
859 else if mclass.kind == extern_kind then
860 modelbuilder.error(self, "Error: Attempt to define attribute {name} in the extern class {mclass}.")
861 end
862
863 # New attribute style
864 var nid2 = self.n_id2
865 var mprop = new MAttribute(mclassdef, "_" + name, private_visibility)
866 var mpropdef = new MAttributeDef(mclassdef, mprop, self.location)
867 self.mpropdef = mpropdef
868 modelbuilder.mpropdef2npropdef[mpropdef] = self
869
870 var readname = name
871 var mreadprop = modelbuilder.try_get_mproperty_by_name(nid2, mclassdef, readname).as(nullable MMethod)
872 if mreadprop == null then
873 var mvisibility = new_property_visibility(modelbuilder, mclassdef, self.n_visibility)
874 mreadprop = new MMethod(mclassdef, readname, mvisibility)
875 if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, false, mreadprop) then return
876 mreadprop.deprecation = mprop.deprecation
877 else
878 if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, true, mreadprop) then return
879 check_redef_property_visibility(modelbuilder, self.n_visibility, mreadprop)
880 end
881 mclassdef.mprop2npropdef[mreadprop] = self
882
883 var mreadpropdef = new MMethodDef(mclassdef, mreadprop, self.location)
884 self.mreadpropdef = mreadpropdef
885 modelbuilder.mpropdef2npropdef[mreadpropdef] = self
886 set_doc(mreadpropdef, modelbuilder)
887 mpropdef.mdoc = mreadpropdef.mdoc
888
889 has_value = n_expr != null or n_block != null
890
891 var atnoinit = self.get_single_annotation("noinit", modelbuilder)
892 if atnoinit != null then
893 noinit = true
894 if has_value then
895 modelbuilder.error(atnoinit, "Error: `noinit` attributes cannot have an initial value")
896 return
897 end
898 end
899
900 var atlazy = self.get_single_annotation("lazy", modelbuilder)
901 var atautoinit = self.get_single_annotation("autoinit", modelbuilder)
902 if atlazy != null or atautoinit != null then
903 if atlazy != null and atautoinit != null then
904 modelbuilder.error(atlazy, "Error: lazy incompatible with autoinit")
905 return
906 end
907 if not has_value then
908 if atlazy != null then
909 modelbuilder.error(atlazy, "Error: a lazy attribute needs a value")
910 else if atautoinit != null then
911 modelbuilder.error(atautoinit, "Error: a autoinit attribute needs a value")
912 end
913 return
914 end
915 is_lazy = true
916 var mlazyprop = new MAttribute(mclassdef, "lazy _" + name, none_visibility)
917 var mlazypropdef = new MAttributeDef(mclassdef, mlazyprop, self.location)
918 self.mlazypropdef = mlazypropdef
919 end
920
921 var atreadonly = self.get_single_annotation("readonly", modelbuilder)
922 if atreadonly != null then
923 if not has_value then
924 modelbuilder.error(atreadonly, "Error: a readonly attribute needs a value")
925 end
926 # No setter, so just leave
927 return
928 end
929
930 var writename = name + "="
931 var atwritable = self.get_single_annotation("writable", modelbuilder)
932 if atwritable != null then
933 if not atwritable.n_args.is_empty then
934 writename = atwritable.arg_as_id(modelbuilder) or else writename
935 end
936 end
937 var mwriteprop = modelbuilder.try_get_mproperty_by_name(nid2, mclassdef, writename).as(nullable MMethod)
938 var nwkwredef: nullable Token = null
939 if atwritable != null then nwkwredef = atwritable.n_kwredef
940 if mwriteprop == null then
941 var mvisibility
942 if atwritable != null then
943 mvisibility = new_property_visibility(modelbuilder, mclassdef, atwritable.n_visibility)
944 else
945 mvisibility = private_visibility
946 end
947 mwriteprop = new MMethod(mclassdef, writename, mvisibility)
948 if not self.check_redef_keyword(modelbuilder, mclassdef, nwkwredef, false, mwriteprop) then return
949 mwriteprop.deprecation = mprop.deprecation
950 else
951 if not self.check_redef_keyword(modelbuilder, mclassdef, nwkwredef or else n_kwredef, true, mwriteprop) then return
952 if atwritable != null then
953 check_redef_property_visibility(modelbuilder, atwritable.n_visibility, mwriteprop)
954 end
955 end
956 mclassdef.mprop2npropdef[mwriteprop] = self
957
958 var mwritepropdef = new MMethodDef(mclassdef, mwriteprop, self.location)
959 self.mwritepropdef = mwritepropdef
960 modelbuilder.mpropdef2npropdef[mwritepropdef] = self
961 mwritepropdef.mdoc = mpropdef.mdoc
962 end
963
964 redef fun build_signature(modelbuilder)
965 do
966 var mpropdef = self.mpropdef
967 if mpropdef == null then return # Error thus skipped
968 var mclassdef = mpropdef.mclassdef
969 var mmodule = mclassdef.mmodule
970 var mtype: nullable MType = null
971
972 var mreadpropdef = self.mreadpropdef
973
974 var ntype = self.n_type
975 if ntype != null then
976 mtype = modelbuilder.resolve_mtype(mmodule, mclassdef, ntype)
977 if mtype == null then return
978 end
979
980 var inherited_type: nullable MType = null
981 # Inherit the type from the getter (usually an abstract getter)
982 if mreadpropdef != null and not mreadpropdef.is_intro then
983 var msignature = mreadpropdef.mproperty.intro.msignature
984 if msignature == null then return # Error, thus skipped
985 inherited_type = msignature.return_mtype
986 if mtype == null then mtype = inherited_type
987 end
988
989 var nexpr = self.n_expr
990 if mtype == null then
991 if nexpr != null then
992 if nexpr isa ANewExpr then
993 mtype = modelbuilder.resolve_mtype(mmodule, mclassdef, nexpr.n_type)
994 else if nexpr isa AIntExpr then
995 var cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Int")
996 if cla != null then mtype = cla.mclass_type
997 else if nexpr isa AFloatExpr then
998 var cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Float")
999 if cla != null then mtype = cla.mclass_type
1000 else if nexpr isa ACharExpr then
1001 var cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Char")
1002 if cla != null then mtype = cla.mclass_type
1003 else if nexpr isa ABoolExpr then
1004 var cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Bool")
1005 if cla != null then mtype = cla.mclass_type
1006 else if nexpr isa ASuperstringExpr then
1007 var cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "String")
1008 if cla != null then mtype = cla.mclass_type
1009 else if nexpr isa AStringFormExpr then
1010 var cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "String")
1011 if cla != null then mtype = cla.mclass_type
1012 else
1013 modelbuilder.error(self, "Error: Untyped attribute {mpropdef}. Implicit typing allowed only for literals and new.")
1014 end
1015
1016 if mtype == null then return
1017 end
1018 else if ntype != null and inherited_type == mtype then
1019 if nexpr isa ANewExpr then
1020 var xmtype = modelbuilder.resolve_mtype(mmodule, mclassdef, nexpr.n_type)
1021 if xmtype == mtype then
1022 modelbuilder.advice(ntype, "useless-type", "Warning: useless type definition")
1023 end
1024 end
1025 end
1026
1027 if mtype == null then
1028 modelbuilder.error(self, "Error: Untyped attribute {mpropdef}")
1029 return
1030 end
1031
1032 mpropdef.static_mtype = mtype
1033
1034 if mreadpropdef != null then
1035 var msignature = new MSignature(new Array[MParameter], mtype)
1036 mreadpropdef.msignature = msignature
1037 end
1038
1039 var mwritepropdef = self.mwritepropdef
1040 if mwritepropdef != null then
1041 var name: String
1042 name = n_id2.text
1043 var mparameter = new MParameter(name, mtype, false)
1044 var msignature = new MSignature([mparameter], null)
1045 mwritepropdef.msignature = msignature
1046 end
1047
1048 var mlazypropdef = self.mlazypropdef
1049 if mlazypropdef != null then
1050 mlazypropdef.static_mtype = modelbuilder.model.get_mclasses_by_name("Bool").first.mclass_type
1051 end
1052 end
1053
1054 redef fun check_signature(modelbuilder)
1055 do
1056 var mpropdef = self.mpropdef
1057 if mpropdef == null then return # Error thus skipped
1058 var ntype = self.n_type
1059 var mtype = self.mpropdef.static_mtype
1060 if mtype == null then return # Error thus skipped
1061
1062 # Lookup for signature in the precursor
1063 # FIXME all precursors should be considered
1064 if not mpropdef.is_intro then
1065 var precursor_type = mpropdef.mproperty.intro.static_mtype
1066 if precursor_type == null then return
1067
1068 if mtype != precursor_type then
1069 modelbuilder.error(ntype.as(not null), "Redef Error: Wrong static type. found {mtype}, expected {precursor_type}.")
1070 return
1071 end
1072 end
1073
1074 # Check getter and setter
1075 var meth = self.mreadpropdef
1076 if meth != null then
1077 self.check_method_signature(modelbuilder, meth)
1078 var node: nullable ANode = ntype
1079 if node == null then node = self
1080 modelbuilder.check_visibility(node, mtype, meth)
1081 end
1082 meth = self.mwritepropdef
1083 if meth != null then
1084 self.check_method_signature(modelbuilder, meth)
1085 var node: nullable ANode = ntype
1086 if node == null then node = self
1087 modelbuilder.check_visibility(node, mtype, meth)
1088 end
1089 end
1090
1091 private fun check_method_signature(modelbuilder: ModelBuilder, mpropdef: MMethodDef)
1092 do
1093 var mclassdef = mpropdef.mclassdef
1094 var mmodule = mclassdef.mmodule
1095 var nsig = self.n_type
1096 var mysignature = mpropdef.msignature
1097 if mysignature == null then return # Error thus skiped
1098
1099 # Lookup for signature in the precursor
1100 # FIXME all precursors should be considered
1101 if not mpropdef.is_intro then
1102 var msignature = mpropdef.mproperty.intro.msignature
1103 if msignature == null then return
1104
1105 if mysignature.arity != msignature.arity then
1106 var node: ANode
1107 if nsig != null then node = nsig else node = self
1108 modelbuilder.error(node, "Redef Error: {mysignature.arity} parameters found, {msignature.arity} expected. Signature is {mpropdef}{msignature}")
1109 return
1110 end
1111 var precursor_ret_type = msignature.return_mtype
1112 var ret_type = mysignature.return_mtype
1113 if ret_type != null and precursor_ret_type == null then
1114 var node: ANode
1115 if nsig != null then node = nsig else node = self
1116 modelbuilder.error(node, "Redef Error: {mpropdef.mproperty} is a procedure, not a function.")
1117 return
1118 end
1119
1120 if mysignature.arity > 0 then
1121 # Check parameters types
1122 for i in [0..mysignature.arity[ do
1123 var myt = mysignature.mparameters[i].mtype
1124 var prt = msignature.mparameters[i].mtype
1125 if not myt.is_subtype(mmodule, mclassdef.bound_mtype, prt) or
1126 not prt.is_subtype(mmodule, mclassdef.bound_mtype, myt) then
1127 var node: ANode
1128 if nsig != null then node = nsig else node = self
1129 modelbuilder.error(node, "Redef Error: Wrong type for parameter `{mysignature.mparameters[i].name}'. found {myt}, expected {prt}.")
1130 end
1131 end
1132 end
1133 if precursor_ret_type != null then
1134 if ret_type == null then
1135 # Inherit the return type
1136 ret_type = precursor_ret_type
1137 else if not ret_type.is_subtype(mmodule, mclassdef.bound_mtype, precursor_ret_type) then
1138 var node: ANode
1139 if nsig != null then node = nsig else node = self
1140 modelbuilder.error(node, "Redef Error: Wrong return type. found {ret_type}, expected {precursor_ret_type}.")
1141 end
1142 end
1143 end
1144 end
1145 end
1146
1147 redef class ATypePropdef
1148 redef type MPROPDEF: MVirtualTypeDef
1149
1150 redef fun build_property(modelbuilder, mclassdef)
1151 do
1152 var name = self.n_id.text
1153 var mprop = modelbuilder.try_get_mproperty_by_name(self.n_id, mclassdef, name)
1154 if mprop == null then
1155 var mvisibility = new_property_visibility(modelbuilder, mclassdef, self.n_visibility)
1156 mprop = new MVirtualTypeProp(mclassdef, name, mvisibility)
1157 for c in name.chars do if c >= 'a' and c<= 'z' then
1158 modelbuilder.warning(n_id, "bad-type-name", "Warning: lowercase in the virtual type {name}")
1159 break
1160 end
1161 if not self.check_redef_keyword(modelbuilder, mclassdef, self.n_kwredef, false, mprop) then return
1162 else
1163 if not self.check_redef_keyword(modelbuilder, mclassdef, self.n_kwredef, true, mprop) then return
1164 assert mprop isa MVirtualTypeProp
1165 check_redef_property_visibility(modelbuilder, self.n_visibility, mprop)
1166 end
1167 mclassdef.mprop2npropdef[mprop] = self
1168
1169 var mpropdef = new MVirtualTypeDef(mclassdef, mprop, self.location)
1170 self.mpropdef = mpropdef
1171 modelbuilder.mpropdef2npropdef[mpropdef] = self
1172 set_doc(mpropdef, modelbuilder)
1173
1174 var atfixed = get_single_annotation("fixed", modelbuilder)
1175 if atfixed != null then
1176 mpropdef.is_fixed = true
1177 end
1178 end
1179
1180 redef fun build_signature(modelbuilder)
1181 do
1182 var mpropdef = self.mpropdef
1183 if mpropdef == null then return # Error thus skipped
1184 var mclassdef = mpropdef.mclassdef
1185 var mmodule = mclassdef.mmodule
1186 var mtype: nullable MType = null
1187
1188 var ntype = self.n_type
1189 mtype = modelbuilder.resolve_mtype(mmodule, mclassdef, ntype)
1190 if mtype == null then return
1191
1192 mpropdef.bound = mtype
1193 # print "{mpropdef}: {mtype}"
1194 end
1195
1196 redef fun check_signature(modelbuilder)
1197 do
1198 var mpropdef = self.mpropdef
1199 if mpropdef == null then return # Error thus skipped
1200
1201 var bound = self.mpropdef.bound
1202 if bound == null then return # Error thus skipped
1203
1204 modelbuilder.check_visibility(n_type, bound, mpropdef)
1205
1206 var mclassdef = mpropdef.mclassdef
1207 var mmodule = mclassdef.mmodule
1208 var anchor = mclassdef.bound_mtype
1209
1210 # Check circularity
1211 if bound isa MVirtualType then
1212 # Slow case: progress on each resolution until: (i) we loop, or (ii) we found a non formal type
1213 var seen = [self.mpropdef.mproperty.mvirtualtype]
1214 loop
1215 if seen.has(bound) then
1216 seen.add(bound)
1217 modelbuilder.error(self, "Error: circularity of virtual type definition: {seen.join(" -> ")}")
1218 return
1219 end
1220 seen.add(bound)
1221 var next = bound.lookup_bound(mmodule, anchor)
1222 if not next isa MVirtualType then break
1223 bound = next
1224 end
1225 end
1226
1227 # Check redefinitions
1228 bound = mpropdef.bound.as(not null)
1229 for p in mpropdef.mproperty.lookup_super_definitions(mmodule, anchor) do
1230 var supbound = p.bound
1231 if supbound == null then break # broken super bound, skip error
1232 if p.is_fixed then
1233 modelbuilder.error(self, "Redef Error: Virtual type {mpropdef.mproperty} is fixed in super-class {p.mclassdef.mclass}")
1234 break
1235 end
1236 if p.mclassdef.mclass == mclassdef.mclass then
1237 # Still a warning to pass existing bad code
1238 modelbuilder.warning(n_type, "refine-type", "Redef Error: a virtual type cannot be refined.")
1239 break
1240 end
1241 if not bound.is_subtype(mmodule, anchor, supbound) then
1242 modelbuilder.error(n_type, "Redef Error: Wrong bound type. Found {bound}, expected a subtype of {supbound}, as in {p}.")
1243 break
1244 end
1245 end
1246 end
1247 end