1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2012 Jean Privat <jean@pryen.org>
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # Analysis and verification of property definitions to instantiate model element
18 module modelize_property
20 intrude import modelize_class
21 private import annotation
23 redef class ToolContext
24 var modelize_property_phase
: Phase = new ModelizePropertyPhase(self, [modelize_class_phase
])
27 private class ModelizePropertyPhase
29 redef fun process_nmodule
(nmodule
)
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
)
38 redef class ModelBuilder
39 # Registration of the npropdef associated to each mpropdef.
41 # Public clients need to use `mpropdef2node` to access stuff.
42 private var mpropdef2npropdef
= new HashMap[MPropDef, APropdef]
44 # Retrieve the associated AST node of a mpropertydef.
45 # This method is used to associate model entity with syntactic entities.
47 # If the property definition is not associated with a node, returns node.
48 fun mpropdef2node
(mpropdef
: MPropDef): nullable ANode
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
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]
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
74 # Build the properties of `nclassdef`.
75 # REQUIRE: all superclasses are built.
76 private fun build_properties
(nclassdef
: AClassdef)
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
])
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
)
93 for npropdef
in nclassdef2
.n_propdefs
do
94 npropdef
.build_signature
(self)
96 for npropdef
in nclassdef2
.n_propdefs
do
97 npropdef
.check_signature
(self)
100 process_default_constructors
(nclassdef
)
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
108 # Introduce or inherit default constructor
109 # This is the last part of `build_properties`.
110 private fun process_default_constructors
(nclassdef
: AClassdef)
112 var mclassdef
= nclassdef
.mclassdef
.as(not null)
114 # Are we a refinement
115 if not mclassdef
.is_intro
then return
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
128 nclassdef
.mfree_init
= mpropdef
129 self.toolcontext
.info
("{mclassdef} gets a free empty constructor {mpropdef}{msignature}", 3)
130 the_root_init_mmethod
= mprop
134 # Is the class forbid constructors?
135 if not mclassdef
.mclass
.kind
.need_init
then return
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
151 if not nclassdef
isa AStdClassdef then return
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
162 var sig
= npropdef
.mpropdef
.msignature
163 if sig
== null then continue # Skip broken method
165 if not npropdef
.mpropdef
.is_intro
then
166 self.error
(at
, "Error: `autoinit` cannot be set on redefinitions")
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
)
175 initializers
.add
(npropdef
.mpropdef
.mproperty
)
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
)
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
)
198 # Add the setter to the list
199 initializers
.add
(msetter
.mproperty
)
204 if the_root_init_mmethod
== null then return
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`?")
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
223 for spd
in spropdefs
do
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(", ")})")
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
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
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
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
271 # Check the visibility of `mtype` as an element of the signature of `mpropdef`.
272 fun check_visibility
(node
: ANode, mtype
: MType, mpropdef
: MPropDef)
274 var mmodule
= mpropdef
.mclassdef
.mmodule
275 var mproperty
= mpropdef
.mproperty
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
291 node
.debug
"Unexpected type {mtype}"
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}`")
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}`")
307 # No error, try to go deeper in generic types
308 if node
isa AType then
309 for a
in node
.n_types
do
311 if t
== null then continue # Error, thus skipped
312 check_visibility
(a
, t
, mpropdef
)
314 else if mtype
isa MGenericType then
315 for t
in mtype
.arguments
do check_visibility
(node
, t
, 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
326 redef class AClassdef
327 var build_properties_is_done
= false
329 # The free init (implicitely constructed by the class if required)
330 var mfree_init
: nullable MMethodDef = null
334 # The base init of the class.
335 # Used to get the common new_msignature and initializers
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
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]
347 # Build the virtual type `SELF` only for introduction `MClassDef`
348 fun build_self_type
(modelbuilder
: ModelBuilder, nclassdef
: AClassdef)
350 if not is_intro
then return
353 var mprop
= modelbuilder
.try_get_mproperty_by_name
(nclassdef
, self, name
)
355 # If SELF type is declared nowherer?
356 if mprop
== null then return
358 # SELF is not a virtual type? it is weird but we ignore it
359 if not mprop
isa MVirtualTypeProp then return
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
]
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.")
372 # SELF must be public
373 if mprop
.visibility
!= public_visibility
then
374 modelbuilder
.error
(nintro
, "Error: the virtual type SELF must be public.")
377 # SELF must not be fixed
378 if intro
.is_fixed
then
379 modelbuilder
.error
(nintro
, "Error: the virtual type SELF cannot be fixed.")
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
393 # The associated main model entity
394 type MPROPDEF: MPropDef
396 # The associated propdef once build by a `ModelBuilder`
397 var mpropdef
: nullable MPROPDEF is writable
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
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
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.")
420 mvisibility
= private_visibility
425 private fun set_doc
(mpropdef
: MPropDef, modelbuilder
: ModelBuilder)
427 var ndoc
= self.n_doc
429 var mdoc
= ndoc
.to_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}`")
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.")
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
449 private fun check_redef_property_visibility
(modelbuilder
: ModelBuilder, nvisibility
: nullable AVisibility, mprop
: MProperty)
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}")
458 private fun check_redef_keyword
(modelbuilder
: ModelBuilder, mclassdef
: MClassDef, kwredef
: nullable Token, need_redef
: Bool, mprop
: MProperty): Bool
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}.")
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.")
468 modelbuilder
.error
(self, "Error: {mprop} is not a top level method.")
473 if mprop
isa MMethod and mprop
.is_root_init
then return true
474 if kwredef
== null then
476 modelbuilder
.error
(self, "Redef error: {mclassdef.mclass}::{mprop.name} is an inherited property. To redefine it, add the redef keyword.")
480 if not need_redef
then
481 modelbuilder
.error
(self, "Error: No property {mclassdef.mclass}::{mprop.name} is inherited. Remove the redef keyword to define a new property.")
490 redef class ASignature
491 # Is the model builder has correctly visited the signature
492 var is_visited
= false
493 # Names of parameters from the AST
494 # REQUIRE: is_visited
495 var param_names
= new Array[String]
496 # Types of parameters from the AST
497 # REQUIRE: is_visited
498 var param_types
= new Array[MType]
499 # Rank of the vararg (of -1 if none)
500 # REQUIRE: is_visited
501 var vararg_rank
: Int = -1
503 var ret_type
: nullable MType = null
505 # Visit and fill information about a signature
506 private fun visit_signature
(modelbuilder
: ModelBuilder, mclassdef
: MClassDef): Bool
508 var mmodule
= mclassdef
.mmodule
509 var param_names
= self.param_names
510 var param_types
= self.param_types
511 for np
in self.n_params
do
512 param_names
.add
(np
.n_id
.text
)
513 var ntype
= np
.n_type
514 if ntype
!= null then
515 var mtype
= modelbuilder
.resolve_mtype
(mmodule
, mclassdef
, ntype
)
516 if mtype
== null then return false # Skip error
517 for i
in [0..param_names
.length-param_types
.length
[ do
518 param_types
.add
(mtype
)
520 if np
.n_dotdotdot
!= null then
521 if self.vararg_rank
!= -1 then
522 modelbuilder
.error
(np
, "Error: {param_names[self.vararg_rank]} is already a vararg")
525 self.vararg_rank
= param_names
.length
- 1
530 var ntype
= self.n_type
531 if ntype
!= null then
532 self.ret_type
= modelbuilder
.resolve_mtype
(mmodule
, mclassdef
, ntype
)
533 if self.ret_type
== null then return false # Skip error
536 self.is_visited
= true
540 # Build a visited signature
541 fun build_signature
(modelbuilder
: ModelBuilder): nullable MSignature
543 if param_names
.length
!= param_types
.length
then
544 # Some parameters are typed, other parameters are not typed.
545 modelbuilder
.error
(self.n_params
[param_types
.length
], "Error: Untyped parameter `{param_names[param_types.length]}'.")
549 var mparameters
= new Array[MParameter]
550 for i
in [0..param_names
.length
[ do
551 var mparameter
= new MParameter(param_names
[i
], param_types
[i
], i
== vararg_rank
)
552 self.n_params
[i
].mparameter
= mparameter
553 mparameters
.add
(mparameter
)
556 var msignature
= new MSignature(mparameters
, ret_type
)
562 # The associated mparameter if any
563 var mparameter
: nullable MParameter = null
566 redef class AMethPropdef
567 redef type MPROPDEF: MMethodDef
570 # Can self be used as a root init?
571 private fun look_like_a_root_init
(modelbuilder
: ModelBuilder, mclassdef
: MClassDef): Bool
573 # Need the `init` keyword
574 if n_kwinit
== null then return false
575 # Need to by anonymous
576 if self.n_methid
!= null then return false
577 # No annotation on itself
578 if get_single_annotation
("old_style_init", modelbuilder
) != null then return false
580 var amod
= self.parent
.parent
.as(AModule)
581 var amoddecl
= amod
.n_moduledecl
582 if amoddecl
!= null then
583 var old
= amoddecl
.get_single_annotation
("old_style_init", modelbuilder
)
584 if old
!= null then return false
587 if self.n_signature
.n_params
.length
> 0 then
588 modelbuilder
.advice
(self, "old-init", "Warning: init with signature in {mclassdef}")
591 # Cannot be private or something
592 if not self.n_visibility
isa APublicVisibility then
593 modelbuilder
.advice
(self, "old-init", "Warning: non-public init in {mclassdef}")
600 redef fun build_property
(modelbuilder
, mclassdef
)
602 var n_kwinit
= n_kwinit
603 var n_kwnew
= n_kwnew
604 var is_init
= n_kwinit
!= null or n_kwnew
!= null
606 var amethodid
= self.n_methid
608 if amethodid
== null then
612 else if n_kwinit
!= null then
615 else if n_kwnew
!= null then
621 else if amethodid
isa AIdMethid then
622 name
= amethodid
.n_id
.text
623 name_node
= amethodid
625 # operator, bracket or assign
626 name
= amethodid
.collect_text
627 name_node
= amethodid
629 if name
== "-" and self.n_signature
.n_params
.length
== 0 then
634 var look_like_a_root_init
= look_like_a_root_init
(modelbuilder
, mclassdef
)
635 var mprop
: nullable MMethod = null
636 if not is_init
or n_kwredef
!= null then mprop
= modelbuilder
.try_get_mproperty_by_name
(name_node
, mclassdef
, name
).as(nullable MMethod)
637 if mprop
== null and look_like_a_root_init
then
638 mprop
= modelbuilder
.the_root_init_mmethod
640 if nb
isa ABlockExpr and nb
.n_expr
.is_empty
and n_doc
== null then
641 modelbuilder
.advice
(self, "useless-init", "Warning: useless empty init in {mclassdef}")
644 if mprop
== null then
645 var mvisibility
= new_property_visibility
(modelbuilder
, mclassdef
, self.n_visibility
)
646 mprop
= new MMethod(mclassdef
, name
, mvisibility
)
647 if look_like_a_root_init
and modelbuilder
.the_root_init_mmethod
== null then
648 modelbuilder
.the_root_init_mmethod
= mprop
649 mprop
.is_root_init
= true
651 mprop
.is_init
= is_init
652 mprop
.is_new
= n_kwnew
!= null
653 if parent
isa ATopClassdef then mprop
.is_toplevel
= true
654 self.check_redef_keyword
(modelbuilder
, mclassdef
, n_kwredef
, false, mprop
)
656 if not self.check_redef_keyword
(modelbuilder
, mclassdef
, n_kwredef
, not self isa AMainMethPropdef, mprop
) then return
657 check_redef_property_visibility
(modelbuilder
, self.n_visibility
, mprop
)
660 # Check name conflicts in the local class for constructors.
662 for p
, n
in mclassdef
.mprop2npropdef
do
663 if p
!= mprop
and p
isa MMethod and p
.name
== name
then
664 check_redef_keyword
(modelbuilder
, mclassdef
, n_kwredef
, false, p
)
670 mclassdef
.mprop2npropdef
[mprop
] = self
672 var mpropdef
= new MMethodDef(mclassdef
, mprop
, self.location
)
674 set_doc
(mpropdef
, modelbuilder
)
676 self.mpropdef
= mpropdef
677 modelbuilder
.mpropdef2npropdef
[mpropdef
] = self
678 if mpropdef
.is_intro
then
679 modelbuilder
.toolcontext
.info
("{mpropdef} introduces new method {mprop.full_name}", 4)
681 modelbuilder
.toolcontext
.info
("{mpropdef} redefines method {mprop.full_name}", 4)
685 redef fun build_signature
(modelbuilder
)
687 var mpropdef
= self.mpropdef
688 if mpropdef
== null then return # Error thus skiped
689 var mclassdef
= mpropdef
.mclassdef
690 var mmodule
= mclassdef
.mmodule
691 var nsig
= self.n_signature
693 if mpropdef
.mproperty
.is_root_init
and not mclassdef
.is_intro
then
694 var root_init
= mclassdef
.mclass
.root_init
695 if root_init
!= null then
696 # Inherit the initializers by refinement
697 mpropdef
.new_msignature
= root_init
.new_msignature
698 assert mpropdef
.initializers
.is_empty
699 mpropdef
.initializers
.add_all root_init
.initializers
703 # Retrieve info from the signature AST
704 var param_names
= new Array[String] # Names of parameters from the AST
705 var param_types
= new Array[MType] # Types of parameters from the AST
707 var ret_type
: nullable MType = null # Return type from the AST
709 if not nsig
.visit_signature
(modelbuilder
, mclassdef
) then return
710 param_names
= nsig
.param_names
711 param_types
= nsig
.param_types
712 vararg_rank
= nsig
.vararg_rank
713 ret_type
= nsig
.ret_type
716 # Look for some signature to inherit
717 # FIXME: do not inherit from the intro, but from the most specific
718 var msignature
: nullable MSignature = null
719 if not mpropdef
.is_intro
then
720 msignature
= mpropdef
.mproperty
.intro
.msignature
721 if msignature
== null then return # Skip error
723 # The local signature is adapted to use the local formal types, if any.
724 msignature
= msignature
.resolve_for
(mclassdef
.mclass
.mclass_type
, mclassdef
.bound_mtype
, mmodule
, false)
726 # Check inherited signature arity
727 if param_names
.length
!= msignature
.arity
then
729 if nsig
!= null then node
= nsig
else node
= self
730 modelbuilder
.error
(node
, "Redef error: {mpropdef} redefines {mpropdef.mproperty.intro} with {param_names.length} parameter(s), {msignature.arity} expected. Signature is {mpropdef}{msignature}")
733 else if mpropdef
.mproperty
.is_init
and not mpropdef
.mproperty
.is_new
then
734 # FIXME UGLY: inherit signature from a super-constructor
735 for msupertype
in mclassdef
.supertypes
do
736 msupertype
= msupertype
.anchor_to
(mmodule
, mclassdef
.bound_mtype
)
737 var candidate
= modelbuilder
.try_get_mproperty_by_name2
(self, mmodule
, msupertype
, mpropdef
.mproperty
.name
)
738 if candidate
!= null then
739 if msignature
== null then
740 msignature
= candidate
.intro
.as(MMethodDef).msignature
747 # Inherit the signature
748 if msignature
!= null and param_names
.length
!= param_types
.length
and param_names
.length
== msignature
.arity
and param_types
.length
== 0 then
749 # Parameters are untyped, thus inherit them
750 param_types
= new Array[MType]
751 for mparameter
in msignature
.mparameters
do
752 param_types
.add
(mparameter
.mtype
)
754 vararg_rank
= msignature
.vararg_rank
756 if msignature
!= null and ret_type
== null then
757 ret_type
= msignature
.return_mtype
760 if param_names
.length
!= param_types
.length
then
761 # Some parameters are typed, other parameters are not typed.
762 modelbuilder
.error
(nsig
.n_params
[param_types
.length
], "Error: Untyped parameter `{param_names[param_types.length]}'.")
766 var mparameters
= new Array[MParameter]
767 for i
in [0..param_names
.length
[ do
768 var mparameter
= new MParameter(param_names
[i
], param_types
[i
], i
== vararg_rank
)
769 if nsig
!= null then nsig
.n_params
[i
].mparameter
= mparameter
770 mparameters
.add
(mparameter
)
773 # In `new`-factories, the return type is by default the classtype.
774 if ret_type
== null and mpropdef
.mproperty
.is_new
then ret_type
= mclassdef
.mclass
.mclass_type
776 msignature
= new MSignature(mparameters
, ret_type
)
777 mpropdef
.msignature
= msignature
778 mpropdef
.is_abstract
= self.get_single_annotation
("abstract", modelbuilder
) != null
779 mpropdef
.is_intern
= self.get_single_annotation
("intern", modelbuilder
) != null
780 mpropdef
.is_extern
= self.n_extern_code_block
!= null or self.get_single_annotation
("extern", modelbuilder
) != null
783 redef fun check_signature
(modelbuilder
)
785 var mpropdef
= self.mpropdef
786 if mpropdef
== null then return # Error thus skiped
787 var mclassdef
= mpropdef
.mclassdef
788 var mmodule
= mclassdef
.mmodule
789 var nsig
= self.n_signature
790 var mysignature
= self.mpropdef
.msignature
791 if mysignature
== null then return # Error thus skiped
793 # Lookup for signature in the precursor
794 # FIXME all precursors should be considered
795 if not mpropdef
.is_intro
then
796 var msignature
= mpropdef
.mproperty
.intro
.msignature
797 if msignature
== null then return
799 var precursor_ret_type
= msignature
.return_mtype
800 var ret_type
= mysignature
.return_mtype
801 if ret_type
!= null and precursor_ret_type
== null then
802 modelbuilder
.error
(nsig
.n_type
.as(not null), "Redef Error: {mpropdef.mproperty} is a procedure, not a function.")
806 if mysignature
.arity
> 0 then
807 # Check parameters types
808 for i
in [0..mysignature
.arity
[ do
809 var myt
= mysignature
.mparameters
[i
].mtype
810 var prt
= msignature
.mparameters
[i
].mtype
811 if not myt
.is_subtype
(mmodule
, mclassdef
.bound_mtype
, prt
) or
812 not prt
.is_subtype
(mmodule
, mclassdef
.bound_mtype
, myt
) then
813 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}.")
817 if precursor_ret_type
!= null then
818 if ret_type
== null then
819 # Inherit the return type
820 ret_type
= precursor_ret_type
821 else if not ret_type
.is_subtype
(mmodule
, mclassdef
.bound_mtype
, precursor_ret_type
) then
822 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}.")
827 if mysignature
.arity
> 0 then
828 # Check parameters visibility
829 for i
in [0..mysignature
.arity
[ do
830 var nt
= nsig
.n_params
[i
].n_type
831 if nt
!= null then modelbuilder
.check_visibility
(nt
, nt
.mtype
.as(not null), mpropdef
)
834 if nt
!= null then modelbuilder
.check_visibility
(nt
, nt
.mtype
.as(not null), mpropdef
)
839 redef class AAttrPropdef
840 redef type MPROPDEF: MAttributeDef
842 # Is the node tagged `noinit`?
845 # Is the node tagged lazy?
848 # Has the node a default value?
849 # Could be through `n_expr` or `n_block`
850 var has_value
= false
852 # The guard associated to a lazy attribute.
853 # Because some engines does not have a working `isset`,
854 # this additional attribute is used to guard the lazy initialization.
855 # TODO: to remove once isset is correctly implemented
856 var mlazypropdef
: nullable MAttributeDef
858 # The associated getter (read accessor) if any
859 var mreadpropdef
: nullable MMethodDef is writable
860 # The associated setter (write accessor) if any
861 var mwritepropdef
: nullable MMethodDef is writable
863 redef fun build_property
(modelbuilder
, mclassdef
)
865 var mclass
= mclassdef
.mclass
868 name
= self.n_id2
.text
870 if mclass
.kind
== interface_kind
or mclassdef
.mclass
.kind
== enum_kind
then
871 modelbuilder
.error
(self, "Error: Attempt to define attribute {name} in the interface {mclass}.")
872 else if mclass
.kind
== enum_kind
then
873 modelbuilder
.error
(self, "Error: Attempt to define attribute {name} in the enum class {mclass}.")
874 else if mclass
.kind
== extern_kind
then
875 modelbuilder
.error
(self, "Error: Attempt to define attribute {name} in the extern class {mclass}.")
878 # New attribute style
879 var nid2
= self.n_id2
880 var mprop
= new MAttribute(mclassdef
, "_" + name
, private_visibility
)
881 var mpropdef
= new MAttributeDef(mclassdef
, mprop
, self.location
)
882 self.mpropdef
= mpropdef
883 modelbuilder
.mpropdef2npropdef
[mpropdef
] = self
886 var mreadprop
= modelbuilder
.try_get_mproperty_by_name
(nid2
, mclassdef
, readname
).as(nullable MMethod)
887 if mreadprop
== null then
888 var mvisibility
= new_property_visibility
(modelbuilder
, mclassdef
, self.n_visibility
)
889 mreadprop
= new MMethod(mclassdef
, readname
, mvisibility
)
890 if not self.check_redef_keyword
(modelbuilder
, mclassdef
, n_kwredef
, false, mreadprop
) then return
891 mreadprop
.deprecation
= mprop
.deprecation
893 if not self.check_redef_keyword
(modelbuilder
, mclassdef
, n_kwredef
, true, mreadprop
) then return
894 check_redef_property_visibility
(modelbuilder
, self.n_visibility
, mreadprop
)
896 mclassdef
.mprop2npropdef
[mreadprop
] = self
898 var mreadpropdef
= new MMethodDef(mclassdef
, mreadprop
, self.location
)
899 self.mreadpropdef
= mreadpropdef
900 modelbuilder
.mpropdef2npropdef
[mreadpropdef
] = self
901 set_doc
(mreadpropdef
, modelbuilder
)
902 mpropdef
.mdoc
= mreadpropdef
.mdoc
904 has_value
= n_expr
!= null or n_block
!= null
906 var atnoinit
= self.get_single_annotation
("noinit", modelbuilder
)
907 if atnoinit
!= null then
910 modelbuilder
.error
(atnoinit
, "Error: `noinit` attributes cannot have an initial value")
915 var atlazy
= self.get_single_annotation
("lazy", modelbuilder
)
916 var atautoinit
= self.get_single_annotation
("autoinit", modelbuilder
)
917 if atlazy
!= null or atautoinit
!= null then
918 if atlazy
!= null and atautoinit
!= null then
919 modelbuilder
.error
(atlazy
, "Error: lazy incompatible with autoinit")
922 if not has_value
then
923 if atlazy
!= null then
924 modelbuilder
.error
(atlazy
, "Error: a lazy attribute needs a value")
925 else if atautoinit
!= null then
926 modelbuilder
.error
(atautoinit
, "Error: a autoinit attribute needs a value")
931 var mlazyprop
= new MAttribute(mclassdef
, "lazy _" + name
, none_visibility
)
932 var mlazypropdef
= new MAttributeDef(mclassdef
, mlazyprop
, self.location
)
933 self.mlazypropdef
= mlazypropdef
936 var atreadonly
= self.get_single_annotation
("readonly", modelbuilder
)
937 if atreadonly
!= null then
938 if not has_value
then
939 modelbuilder
.error
(atreadonly
, "Error: a readonly attribute needs a value")
941 # No setter, so just leave
945 var writename
= name
+ "="
946 var atwritable
= self.get_single_annotation
("writable", modelbuilder
)
947 if atwritable
!= null then
948 if not atwritable
.n_args
.is_empty
then
949 writename
= atwritable
.arg_as_id
(modelbuilder
) or else writename
952 var mwriteprop
= modelbuilder
.try_get_mproperty_by_name
(nid2
, mclassdef
, writename
).as(nullable MMethod)
953 var nwkwredef
: nullable Token = null
954 if atwritable
!= null then nwkwredef
= atwritable
.n_kwredef
955 if mwriteprop
== null then
957 if atwritable
!= null then
958 mvisibility
= new_property_visibility
(modelbuilder
, mclassdef
, atwritable
.n_visibility
)
960 mvisibility
= private_visibility
962 mwriteprop
= new MMethod(mclassdef
, writename
, mvisibility
)
963 if not self.check_redef_keyword
(modelbuilder
, mclassdef
, nwkwredef
, false, mwriteprop
) then return
964 mwriteprop
.deprecation
= mprop
.deprecation
966 if not self.check_redef_keyword
(modelbuilder
, mclassdef
, nwkwredef
or else n_kwredef
, true, mwriteprop
) then return
967 if atwritable
!= null then
968 check_redef_property_visibility
(modelbuilder
, atwritable
.n_visibility
, mwriteprop
)
971 mclassdef
.mprop2npropdef
[mwriteprop
] = self
973 var mwritepropdef
= new MMethodDef(mclassdef
, mwriteprop
, self.location
)
974 self.mwritepropdef
= mwritepropdef
975 modelbuilder
.mpropdef2npropdef
[mwritepropdef
] = self
976 mwritepropdef
.mdoc
= mpropdef
.mdoc
979 redef fun build_signature
(modelbuilder
)
981 var mpropdef
= self.mpropdef
982 if mpropdef
== null then return # Error thus skipped
983 var mclassdef
= mpropdef
.mclassdef
984 var mmodule
= mclassdef
.mmodule
985 var mtype
: nullable MType = null
987 var mreadpropdef
= self.mreadpropdef
989 var ntype
= self.n_type
990 if ntype
!= null then
991 mtype
= modelbuilder
.resolve_mtype
(mmodule
, mclassdef
, ntype
)
992 if mtype
== null then return
995 var inherited_type
: nullable MType = null
996 # Inherit the type from the getter (usually an abstract getter)
997 if mreadpropdef
!= null and not mreadpropdef
.is_intro
then
998 var msignature
= mreadpropdef
.mproperty
.intro
.msignature
999 if msignature
== null then return # Error, thus skipped
1000 inherited_type
= msignature
.return_mtype
1001 if inherited_type
!= null then
1002 # The inherited type is adapted to use the local formal types, if any.
1003 inherited_type
= inherited_type
.resolve_for
(mclassdef
.mclass
.mclass_type
, mclassdef
.bound_mtype
, mmodule
, false)
1004 if mtype
== null then mtype
= inherited_type
1008 var nexpr
= self.n_expr
1009 if mtype
== null then
1010 if nexpr
!= null then
1011 if nexpr
isa ANewExpr then
1012 mtype
= modelbuilder
.resolve_mtype
(mmodule
, mclassdef
, nexpr
.n_type
)
1013 else if nexpr
isa AIntExpr then
1014 var cla
= modelbuilder
.try_get_mclass_by_name
(nexpr
, mmodule
, "Int")
1015 if cla
!= null then mtype
= cla
.mclass_type
1016 else if nexpr
isa AFloatExpr then
1017 var cla
= modelbuilder
.try_get_mclass_by_name
(nexpr
, mmodule
, "Float")
1018 if cla
!= null then mtype
= cla
.mclass_type
1019 else if nexpr
isa ACharExpr then
1020 var cla
= modelbuilder
.try_get_mclass_by_name
(nexpr
, mmodule
, "Char")
1021 if cla
!= null then mtype
= cla
.mclass_type
1022 else if nexpr
isa ABoolExpr then
1023 var cla
= modelbuilder
.try_get_mclass_by_name
(nexpr
, mmodule
, "Bool")
1024 if cla
!= null then mtype
= cla
.mclass_type
1025 else if nexpr
isa ASuperstringExpr then
1026 var cla
= modelbuilder
.try_get_mclass_by_name
(nexpr
, mmodule
, "String")
1027 if cla
!= null then mtype
= cla
.mclass_type
1028 else if nexpr
isa AStringFormExpr then
1029 var cla
= modelbuilder
.try_get_mclass_by_name
(nexpr
, mmodule
, "String")
1030 if cla
!= null then mtype
= cla
.mclass_type
1032 modelbuilder
.error
(self, "Error: Untyped attribute {mpropdef}. Implicit typing allowed only for literals and new.")
1035 if mtype
== null then return
1037 else if ntype
!= null and inherited_type
== mtype
then
1038 if nexpr
isa ANewExpr then
1039 var xmtype
= modelbuilder
.resolve_mtype
(mmodule
, mclassdef
, nexpr
.n_type
)
1040 if xmtype
== mtype
then
1041 modelbuilder
.advice
(ntype
, "useless-type", "Warning: useless type definition")
1046 if mtype
== null then
1047 modelbuilder
.error
(self, "Error: Untyped attribute {mpropdef}")
1051 mpropdef
.static_mtype
= mtype
1053 if mreadpropdef
!= null then
1054 var msignature
= new MSignature(new Array[MParameter], mtype
)
1055 mreadpropdef
.msignature
= msignature
1058 var mwritepropdef
= self.mwritepropdef
1059 if mwritepropdef
!= null then
1062 var mparameter
= new MParameter(name
, mtype
, false)
1063 var msignature
= new MSignature([mparameter
], null)
1064 mwritepropdef
.msignature
= msignature
1067 var mlazypropdef
= self.mlazypropdef
1068 if mlazypropdef
!= null then
1069 mlazypropdef
.static_mtype
= modelbuilder
.model
.get_mclasses_by_name
("Bool").first
.mclass_type
1073 redef fun check_signature
(modelbuilder
)
1075 var mpropdef
= self.mpropdef
1076 if mpropdef
== null then return # Error thus skipped
1077 var ntype
= self.n_type
1078 var mtype
= self.mpropdef
.static_mtype
1079 if mtype
== null then return # Error thus skipped
1081 # Lookup for signature in the precursor
1082 # FIXME all precursors should be considered
1083 if not mpropdef
.is_intro
then
1084 var precursor_type
= mpropdef
.mproperty
.intro
.static_mtype
1085 if precursor_type
== null then return
1087 if mtype
!= precursor_type
then
1088 modelbuilder
.error
(ntype
.as(not null), "Redef Error: Wrong static type. found {mtype}, expected {precursor_type}.")
1093 # Check getter and setter
1094 var meth
= self.mreadpropdef
1095 if meth
!= null then
1096 self.check_method_signature
(modelbuilder
, meth
)
1097 var node
: nullable ANode = ntype
1098 if node
== null then node
= self
1099 modelbuilder
.check_visibility
(node
, mtype
, meth
)
1101 meth
= self.mwritepropdef
1102 if meth
!= null then
1103 self.check_method_signature
(modelbuilder
, meth
)
1104 var node
: nullable ANode = ntype
1105 if node
== null then node
= self
1106 modelbuilder
.check_visibility
(node
, mtype
, meth
)
1110 private fun check_method_signature
(modelbuilder
: ModelBuilder, mpropdef
: MMethodDef)
1112 var mclassdef
= mpropdef
.mclassdef
1113 var mmodule
= mclassdef
.mmodule
1114 var nsig
= self.n_type
1115 var mysignature
= mpropdef
.msignature
1116 if mysignature
== null then return # Error thus skiped
1118 # Lookup for signature in the precursor
1119 # FIXME all precursors should be considered
1120 if not mpropdef
.is_intro
then
1121 var msignature
= mpropdef
.mproperty
.intro
.msignature
1122 if msignature
== null then return
1124 if mysignature
.arity
!= msignature
.arity
then
1126 if nsig
!= null then node
= nsig
else node
= self
1127 modelbuilder
.error
(node
, "Redef Error: {mysignature.arity} parameters found, {msignature.arity} expected. Signature is {mpropdef}{msignature}")
1130 var precursor_ret_type
= msignature
.return_mtype
1131 var ret_type
= mysignature
.return_mtype
1132 if ret_type
!= null and precursor_ret_type
== null then
1134 if nsig
!= null then node
= nsig
else node
= self
1135 modelbuilder
.error
(node
, "Redef Error: {mpropdef.mproperty} is a procedure, not a function.")
1139 if mysignature
.arity
> 0 then
1140 # Check parameters types
1141 for i
in [0..mysignature
.arity
[ do
1142 var myt
= mysignature
.mparameters
[i
].mtype
1143 var prt
= msignature
.mparameters
[i
].mtype
1144 if not myt
.is_subtype
(mmodule
, mclassdef
.bound_mtype
, prt
) or
1145 not prt
.is_subtype
(mmodule
, mclassdef
.bound_mtype
, myt
) then
1147 if nsig
!= null then node
= nsig
else node
= self
1148 modelbuilder
.error
(node
, "Redef Error: Wrong type for parameter `{mysignature.mparameters[i].name}'. found {myt}, expected {prt}.")
1152 if precursor_ret_type
!= null then
1153 if ret_type
== null then
1154 # Inherit the return type
1155 ret_type
= precursor_ret_type
1156 else if not ret_type
.is_subtype
(mmodule
, mclassdef
.bound_mtype
, precursor_ret_type
) then
1158 if nsig
!= null then node
= nsig
else node
= self
1159 modelbuilder
.error
(node
, "Redef Error: Wrong return type. found {ret_type}, expected {precursor_ret_type}.")
1166 redef class ATypePropdef
1167 redef type MPROPDEF: MVirtualTypeDef
1169 redef fun build_property
(modelbuilder
, mclassdef
)
1171 var name
= self.n_id
.text
1172 var mprop
= modelbuilder
.try_get_mproperty_by_name
(self.n_id
, mclassdef
, name
)
1173 if mprop
== null then
1174 var mvisibility
= new_property_visibility
(modelbuilder
, mclassdef
, self.n_visibility
)
1175 mprop
= new MVirtualTypeProp(mclassdef
, name
, mvisibility
)
1176 for c
in name
.chars
do if c
>= 'a' and c
<= 'z' then
1177 modelbuilder
.warning
(n_id
, "bad-type-name", "Warning: lowercase in the virtual type {name}")
1180 if not self.check_redef_keyword
(modelbuilder
, mclassdef
, self.n_kwredef
, false, mprop
) then return
1182 if not self.check_redef_keyword
(modelbuilder
, mclassdef
, self.n_kwredef
, true, mprop
) then return
1183 assert mprop
isa MVirtualTypeProp
1184 check_redef_property_visibility
(modelbuilder
, self.n_visibility
, mprop
)
1186 mclassdef
.mprop2npropdef
[mprop
] = self
1188 var mpropdef
= new MVirtualTypeDef(mclassdef
, mprop
, self.location
)
1189 self.mpropdef
= mpropdef
1190 modelbuilder
.mpropdef2npropdef
[mpropdef
] = self
1191 if mpropdef
.is_intro
then
1192 modelbuilder
.toolcontext
.info
("{mpropdef} introduces new type {mprop.full_name}", 4)
1194 modelbuilder
.toolcontext
.info
("{mpropdef} redefines type {mprop.full_name}", 4)
1196 set_doc
(mpropdef
, modelbuilder
)
1198 var atfixed
= get_single_annotation
("fixed", modelbuilder
)
1199 if atfixed
!= null then
1200 mpropdef
.is_fixed
= true
1204 redef fun build_signature
(modelbuilder
)
1206 var mpropdef
= self.mpropdef
1207 if mpropdef
== null then return # Error thus skipped
1208 var mclassdef
= mpropdef
.mclassdef
1209 var mmodule
= mclassdef
.mmodule
1210 var mtype
: nullable MType = null
1212 var ntype
= self.n_type
1213 mtype
= modelbuilder
.resolve_mtype
(mmodule
, mclassdef
, ntype
)
1214 if mtype
== null then return
1216 mpropdef
.bound
= mtype
1217 # print "{mpropdef}: {mtype}"
1220 redef fun check_signature
(modelbuilder
)
1222 var mpropdef
= self.mpropdef
1223 if mpropdef
== null then return # Error thus skipped
1225 var bound
= self.mpropdef
.bound
1226 if bound
== null then return # Error thus skipped
1228 modelbuilder
.check_visibility
(n_type
, bound
, mpropdef
)
1230 var mclassdef
= mpropdef
.mclassdef
1231 var mmodule
= mclassdef
.mmodule
1232 var anchor
= mclassdef
.bound_mtype
1235 if bound
isa MVirtualType then
1236 # Slow case: progress on each resolution until: (i) we loop, or (ii) we found a non formal type
1237 var seen
= [self.mpropdef
.mproperty
.mvirtualtype
]
1239 if seen
.has
(bound
) then
1241 modelbuilder
.error
(self, "Error: circularity of virtual type definition: {seen.join(" -> ")}")
1245 var next
= bound
.lookup_bound
(mmodule
, anchor
)
1246 if not next
isa MVirtualType then break
1251 # Check redefinitions
1252 bound
= mpropdef
.bound
.as(not null)
1253 for p
in mpropdef
.mproperty
.lookup_super_definitions
(mmodule
, anchor
) do
1254 var supbound
= p
.bound
1255 if supbound
== null then break # broken super bound, skip error
1257 modelbuilder
.error
(self, "Redef Error: Virtual type {mpropdef.mproperty} is fixed in super-class {p.mclassdef.mclass}")
1260 if p
.mclassdef
.mclass
== mclassdef
.mclass
then
1261 # Still a warning to pass existing bad code
1262 modelbuilder
.warning
(n_type
, "refine-type", "Redef Error: a virtual type cannot be refined.")
1265 if not bound
.is_subtype
(mmodule
, anchor
, supbound
) then
1266 modelbuilder
.error
(n_type
, "Redef Error: Wrong bound type. Found {bound}, expected a subtype of {supbound}, as in {p}.")