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 # Intraprocedural resolution of static types and OO-services
18 # By OO-services we mean message sending, attribute access, instantiation, etc.
22 import modelize_property
26 redef class ToolContext
27 var typing_phase
: Phase = new TypingPhase(self, [flow_phase
, modelize_property_phase
, local_var_init_phase
])
30 private class TypingPhase
32 redef fun process_npropdef
(npropdef
) do npropdef
.do_typing
(toolcontext
.modelbuilder
)
35 private class TypeVisitor
36 var modelbuilder
: ModelBuilder
37 var nclassdef
: AClassdef
38 var mpropdef
: MPropDef
40 var selfvariable
: Variable = new Variable("self")
42 init(modelbuilder
: ModelBuilder, nclassdef
: AClassdef, mpropdef
: MPropDef)
44 self.modelbuilder
= modelbuilder
45 self.nclassdef
= nclassdef
46 self.mpropdef
= mpropdef
48 var mclass
= nclassdef
.mclassdef
.mclass
50 var selfvariable
= new Variable("self")
51 self.selfvariable
= selfvariable
52 selfvariable
.declared_type
= mclass
.mclass_type
55 fun mmodule
: MModule do return self.nclassdef
.mclassdef
.mmodule
57 fun anchor
: MClassType do return self.nclassdef
.mclassdef
.bound_mtype
59 fun anchor_to
(mtype
: MType): MType
61 var mmodule
= self.nclassdef
.mclassdef
.mmodule
62 var anchor
= self.nclassdef
.mclassdef
.bound_mtype
63 return mtype
.anchor_to
(mmodule
, anchor
)
66 fun is_subtype
(sub
, sup
: MType): Bool
68 var mmodule
= self.nclassdef
.mclassdef
.mmodule
69 var anchor
= self.nclassdef
.mclassdef
.bound_mtype
70 return sub
.is_subtype
(mmodule
, anchor
, sup
)
73 fun resolve_for
(mtype
, subtype
: MType, for_self
: Bool): MType
75 var mmodule
= self.nclassdef
.mclassdef
.mmodule
76 var anchor
= self.nclassdef
.mclassdef
.bound_mtype
77 #print "resolve_for {mtype} sub={subtype} forself={for_self} mmodule={mmodule} anchor={anchor}"
78 var res
= mtype
.resolve_for
(subtype
, anchor
, mmodule
, not for_self
)
82 # Retrieve the signature of a `MMethodDef` resolved for a specific call.
83 # This method is an helper to symplify the query on the model.
85 # Note: `for_self` indicates if the reciever is self or not.
86 # If yes, virtual types are not resolved.
87 fun resolve_signature_for
(mmethoddef
: MMethodDef, recv
: MType, for_self
: Bool): MSignature
89 return self.resolve_for
(mmethoddef
.msignature
.as(not null), recv
, for_self
).as(MSignature)
92 # Check that `sub` is a subtype of `sup`.
93 # If `sub` is not a valud suptype, then display an error on `node` an return null.
94 # If `sub` is a safe subtype of `sup` then return `sub`.
95 # If `sub` is an insafe subtype (ie an imlicit cast is required), then return `sup`.
97 # The point of the return type is to determinate the usable type on an expression:
98 # If the suptype is safe, then the return type is the one on the expression typed by `sub`.
99 # Is the subtype is unsafe, then the return type is the one of an implicit cast on `sup`.
100 fun check_subtype
(node
: ANode, sub
, sup
: MType): nullable MType
102 if self.is_subtype
(sub
, sup
) then return sub
103 if self.is_subtype
(sub
, self.anchor_to
(sup
)) then
104 # FIXME workarround to the current unsafe typing policy. To remove once fixed virtual types exists.
105 #node.debug("Unsafe typing: expected {sup}, got {sub}")
108 self.modelbuilder
.error
(node
, "Type error: expected {sup}, got {sub}")
112 # Visit an expression and do not care about the return value
113 fun visit_stmt
(nexpr
: nullable AExpr)
115 if nexpr
== null then return
116 nexpr
.accept_typing
(self)
119 # Visit an expression and expects that it is not a statement
120 # Return the type of the expression
121 # Display an error and return null if:
122 # * the type cannot be determined or
123 # * `nexpr` is a statement
124 fun visit_expr
(nexpr
: AExpr): nullable MType
126 nexpr
.accept_typing
(self)
127 var mtype
= nexpr
.mtype
128 if mtype
!= null then return mtype
129 if not nexpr
.is_typed
then
130 if not self.modelbuilder
.toolcontext
.error_count
> 0 then # check that there is really an error
131 if self.modelbuilder
.toolcontext
.verbose_level
> 1 then
132 nexpr
.debug
("No return type but no error.")
135 return null # forward error
137 self.error
(nexpr
, "Type error: expected expression.")
141 # Visit an expression and expect its static type is a least a `sup`
142 # Return the type of the expression or null if
143 # * the type cannot be determined or
144 # * `nexpr` is a statement or
145 # * `nexpr` is not a `sup`
146 fun visit_expr_subtype
(nexpr
: AExpr, sup
: nullable MType): nullable MType
148 var sub
= visit_expr
(nexpr
)
149 if sub
== null then return null # Forward error
151 if sup
== null then return null # Forward error
153 var res
= check_subtype
(nexpr
, sub
, sup
)
155 nexpr
.implicit_cast_to
= res
160 # Visit an expression and expect its static type is a `Bool`
161 # Return the type of the expression or null if
162 # * the type cannot be determined or
163 # * `nexpr` is a statement or
164 # * `nexpr` is not a `Bool`
165 fun visit_expr_bool
(nexpr
: AExpr): nullable MType
167 return self.visit_expr_subtype
(nexpr
, self.type_bool
(nexpr
))
171 private fun visit_expr_cast
(node
: ANode, nexpr
: AExpr, ntype
: AType): nullable MType
173 var sub
= visit_expr
(nexpr
)
174 if sub
== null then return null # Forward error
176 var sup
= self.resolve_mtype
(ntype
)
177 if sup
== null then return null # Forward error
179 var mmodule
= self.nclassdef
.mclassdef
.mmodule
180 var anchor
= self.nclassdef
.mclassdef
.bound_mtype
182 self.modelbuilder
.warning
(node
, "Warning: Expression is already a {sup}.")
183 else if self.is_subtype
(sub
, sup
) and not sup
.need_anchor
then
184 self.modelbuilder
.warning
(node
, "Warning: Expression is already a {sup} since it is a {sub}.")
189 fun try_get_mproperty_by_name2
(anode
: ANode, mtype
: MType, name
: String): nullable MProperty
191 return self.modelbuilder
.try_get_mproperty_by_name2
(anode
, self.nclassdef
.mclassdef
.mmodule
, mtype
, name
)
194 fun resolve_mtype
(node
: AType): nullable MType
196 return self.modelbuilder
.resolve_mtype
(self.nclassdef
, node
)
199 fun try_get_mclass
(node
: ANode, name
: String): nullable MClass
201 var mmodule
= self.nclassdef
.mclassdef
.mmodule
202 var mclass
= modelbuilder
.try_get_mclass_by_name
(node
, mmodule
, name
)
206 fun get_mclass
(node
: ANode, name
: String): nullable MClass
208 var mmodule
= self.nclassdef
.mclassdef
.mmodule
209 var mclass
= modelbuilder
.try_get_mclass_by_name
(node
, mmodule
, name
)
210 if mclass
== null then
211 self.modelbuilder
.error
(node
, "Type Error: missing primitive class `{name}'.")
216 fun type_bool
(node
: ANode): nullable MType
218 var mclass
= self.get_mclass
(node
, "Bool")
219 if mclass
== null then return null
220 return mclass
.mclass_type
223 fun get_method
(node
: ANode, recvtype
: MType, name
: String, recv_is_self
: Bool): nullable CallSite
225 var unsafe_type
= self.anchor_to
(recvtype
)
227 #debug("recv: {recvtype} (aka {unsafe_type})")
228 if recvtype
isa MNullType then
229 self.error
(node
, "Error: Method '{name}' call on 'null'.")
233 var mproperty
= self.try_get_mproperty_by_name2
(node
, unsafe_type
, name
)
234 if mproperty
== null then
235 #self.modelbuilder.error(node, "Type error: property {name} not found in {unsafe_type} (ie {recvtype})")
237 self.modelbuilder
.error
(node
, "Error: Method or variable '{name}' unknown in {recvtype}.")
239 self.modelbuilder
.error
(node
, "Error: Method '{name}' doesn't exists in {recvtype}.")
244 assert mproperty
isa MMethod
245 if mproperty
.visibility
== protected_visibility
and not recv_is_self
and self.mmodule
.visibility_for
(mproperty
.intro_mclassdef
.mmodule
) < intrude_visibility
then
246 self.modelbuilder
.error
(node
, "Error: Method '{name}' is protected and can only acceded by self. {mproperty.intro_mclassdef.mmodule.visibility_for(self.mmodule)}")
250 var propdefs
= mproperty
.lookup_definitions
(self.mmodule
, unsafe_type
)
252 if propdefs
.length
== 0 then
253 self.modelbuilder
.error
(node
, "Type error: no definition found for property {name} in {unsafe_type}")
255 else if propdefs
.length
== 1 then
256 mpropdef
= propdefs
.first
258 self.modelbuilder
.warning
(node
, "Warning: confliting property definitions for property {name} in {unsafe_type}: {propdefs.join(" ")}")
259 mpropdef
= mproperty
.intro
263 var msignature
= self.resolve_signature_for
(mpropdef
, recvtype
, recv_is_self
)
265 var erasure_cast
= false
266 var rettype
= mpropdef
.msignature
.return_mtype
267 if not recv_is_self
and rettype
!= null then
268 if rettype
isa MNullableType then rettype
= rettype
.mtype
269 if rettype
isa MParameterType then
270 var erased_rettype
= msignature
.return_mtype
271 assert erased_rettype
!= null
272 #node.debug("Erasure cast: Really a {rettype} but unsafely a {erased_rettype}")
277 var callsite
= new CallSite(node
, recvtype
, mmodule
, anchor
, recv_is_self
, mproperty
, mpropdef
, msignature
, erasure_cast
)
281 # Visit the expressions of args and cheik their conformity with the corresponding typi in signature
282 # The point of this method is to handle varargs correctly
283 # Note: The signature must be correctly adapted
284 fun check_signature
(node
: ANode, args
: Array[AExpr], name
: String, msignature
: MSignature): Bool
286 var vararg_rank
= msignature
.vararg_rank
287 if vararg_rank
>= 0 then
288 if args
.length
< msignature
.arity
then
289 #self.modelbuilder.error(node, "Error: Incorrect number of parameters. Got {args.length}, expected at least {msignature.arity}. Signature is {msignature}")
290 self.modelbuilder
.error
(node
, "Error: arity mismatch; prototype is '{name}{msignature}'")
293 else if args
.length
!= msignature
.arity
then
294 self.modelbuilder
.error
(node
, "Error: Incorrect number of parameters. Got {args.length}, expected {msignature.arity}. Signature is {msignature}")
298 #debug("CALL {unsafe_type}.{msignature}")
300 var vararg_decl
= args
.length
- msignature
.arity
301 for i
in [0..msignature
.arity
[ do
303 if i
== vararg_rank
then continue # skip the vararg
304 if i
> vararg_rank
then
307 var paramtype
= msignature
.mparameters
[i
].mtype
308 self.visit_expr_subtype
(args
[j
], paramtype
)
310 if vararg_rank
>= 0 then
311 var varargs
= new Array[AExpr]
312 var paramtype
= msignature
.mparameters
[vararg_rank
].mtype
313 for j
in [vararg_rank
..vararg_rank
+vararg_decl
] do
315 self.visit_expr_subtype
(args
[j
], paramtype
)
321 fun error
(node
: ANode, message
: String)
323 self.modelbuilder
.toolcontext
.error
(node
.hot_location
, message
)
326 fun get_variable
(node
: AExpr, variable
: Variable): nullable MType
328 var flow
= node
.after_flow_context
330 self.error
(node
, "No context!")
334 if flow
.vars
.has_key
(variable
) then
335 return flow
.vars
[variable
]
337 #node.debug("*** START Collected for {variable}")
338 var mtypes
= flow
.collect_types
(variable
)
339 #node.debug("**** END Collected for {variable}")
340 if mtypes
== null or mtypes
.length
== 0 then
341 return variable
.declared_type
342 else if mtypes
.length
== 1 then
345 var res
= merge_types
(node
,mtypes
)
346 if res
== null then res
= variable
.declared_type
352 fun set_variable
(node
: AExpr, variable
: Variable, mtype
: nullable MType)
354 var flow
= node
.after_flow_context
357 flow
.set_var
(variable
, mtype
)
360 fun merge_types
(node
: ANode, col
: Array[nullable MType]): nullable MType
362 if col
.length
== 1 then return col
.first
363 var res
= new Array[nullable MType]
365 if t1
== null then continue # return null
368 if t2
== null then continue # return null
369 if t2
isa MNullableType or t2
isa MNullType then
372 if not is_subtype
(t2
, t1
) then found
= false
375 #print "merge {col.join(" ")} -> {t1}"
379 #self.modelbuilder.warning(node, "Type Error: {col.length} conflicting types: <{col.join(", ")}>")
384 # A specific method call site with its associated informations.
386 # The assiciated node for location
389 # The static type of the receiver (possibly unresolved)
392 # The module where the callsite is present
395 # The anchor to use with `recv` or `msignature`
396 var anchor
: nullable MClassType
398 # Is the receiver self?
399 # If "for_self", virtual types of the signature are keeped
400 # If "not_for_self", virtual type are erased
401 var recv_is_self
: Bool
403 # The designated method
404 var mproperty
: MMethod
406 # The statically designated method definition
407 # The most specif one, it is.
408 var mpropdef
: MMethodDef
410 # The resolved signature for the receiver
411 var msignature
: MSignature
413 # Is a implicit cast required on erasure typing policy?
414 var erasure_cast
: Bool
416 private fun check_signature
(v
: TypeVisitor, args
: Array[AExpr]): Bool
418 return v
.check_signature
(self.node
, args
, self.mproperty
.name
, self.msignature
)
423 # The declared type of the variable
424 var declared_type
: nullable MType
427 redef class FlowContext
428 # Store changes of types because of type evolution
429 private var vars
: HashMap[Variable, nullable MType] = new HashMap[Variable, nullable MType]
430 private var cache
: HashMap[Variable, nullable Array[nullable MType]] = new HashMap[Variable, nullable Array[nullable MType]]
432 # Adapt the variable to a static type
433 # Warning1: do not modify vars directly.
434 # Warning2: sub-flow may have cached a unadapted variabial
435 private fun set_var
(variable
: Variable, mtype
: nullable MType)
437 self.vars
[variable
] = mtype
438 self.cache
.keys
.remove
(variable
)
441 private fun collect_types
(variable
: Variable): nullable Array[nullable MType]
443 if cache
.has_key
(variable
) then
444 return cache
[variable
]
446 var res
: nullable Array[nullable MType] = null
447 if vars
.has_key
(variable
) then
448 var mtype
= vars
[variable
]
450 else if self.previous
.is_empty
then
452 res
= [variable
.declared_type
]
454 for flow
in self.previous
do
455 if flow
.is_unreachable
then continue
456 var r2
= flow
.collect_types
(variable
)
457 if r2
== null then continue
462 if not res
.has
(t
) then res
.add
(t
)
467 cache
[variable
] = res
473 # The entry point of the whole typing analysis
474 fun do_typing
(modelbuilder
: ModelBuilder)
478 # The variable associated to the reciever (if any)
479 var selfvariable
: nullable Variable
482 redef class AConcreteMethPropdef
483 redef fun do_typing
(modelbuilder
: ModelBuilder)
485 var nclassdef
= self.parent
.as(AClassdef)
486 var mpropdef
= self.mpropdef
.as(not null)
487 var v
= new TypeVisitor(modelbuilder
, nclassdef
, mpropdef
)
488 self.selfvariable
= v
.selfvariable
490 var nblock
= self.n_block
491 if nblock
== null then return
493 var mmethoddef
= self.mpropdef
.as(not null)
494 for i
in [0..mmethoddef
.msignature
.arity
[ do
495 var mtype
= mmethoddef
.msignature
.mparameters
[i
].mtype
496 if mmethoddef
.msignature
.vararg_rank
== i
then
497 var arrayclass
= v
.get_mclass
(self.n_signature
.n_params
[i
], "Array")
498 if arrayclass
== null then return # Skip error
499 mtype
= arrayclass
.get_mtype
([mtype
])
501 var variable
= self.n_signature
.n_params
[i
].variable
502 assert variable
!= null
503 variable
.declared_type
= mtype
507 if not nblock
.after_flow_context
.is_unreachable
and mmethoddef
.msignature
.return_mtype
!= null then
508 # We reach the end of the function without having a return, it is bad
509 v
.error
(self, "Control error: Reached end of function (a 'return' with a value was expected).")
514 redef class AAttrPropdef
515 redef fun do_typing
(modelbuilder
: ModelBuilder)
517 var nclassdef
= self.parent
.as(AClassdef)
518 var v
= new TypeVisitor(modelbuilder
, nclassdef
, self.mpropdef
.as(not null))
519 self.selfvariable
= v
.selfvariable
521 var nexpr
= self.n_expr
522 if nexpr
!= null then
523 var mtype
= self.mpropdef
.static_mtype
524 v
.visit_expr_subtype
(nexpr
, mtype
)
532 # The static type of the expression.
533 # null if self is a statement or in case of error
534 var mtype
: nullable MType = null
536 # Is the statement correctly typed?
537 # Used to distinguish errors and statements when `mtype == null`
538 var is_typed
: Bool = false
540 # If required, the following implicit cast `.as(XXX)`
541 # Such a cast may by required after evaluating the expression when
542 # a unsafe operation is detected (silently accepted by the Nit language).
543 # The attribute is computed by `check_subtype`
544 var implicit_cast_to
: nullable MType = null
546 # Return the variable read (if any)
547 # Used to perform adaptive typing
548 fun its_variable
: nullable Variable do return null
550 private fun accept_typing
(v
: TypeVisitor)
552 v
.error
(self, "no implemented accept_typing for {self.class_name}")
556 redef class ABlockExpr
557 redef fun accept_typing
(v
)
559 for e
in self.n_expr
do v
.visit_stmt
(e
)
563 # The type of a blockexpr is the one of the last expression (or null if empty)
566 if self.n_expr
.is_empty
then return null
567 return self.n_expr
.last
.mtype
571 redef class AVardeclExpr
572 redef fun accept_typing
(v
)
574 var variable
= self.variable
575 if variable
== null then return # Skip error
577 var ntype
= self.n_type
578 var mtype
: nullable MType
579 if ntype
== null then
582 mtype
= v
.resolve_mtype
(ntype
)
583 if mtype
== null then return # Skip error
586 var nexpr
= self.n_expr
587 if nexpr
!= null then
588 if mtype
!= null then
589 v
.visit_expr_subtype
(nexpr
, mtype
)
591 mtype
= v
.visit_expr
(nexpr
)
592 if mtype
== null then return # Skip error
597 if mtype
== null or mtype
isa MNullType then
598 decltype
= v
.get_mclass
(self, "Object").mclass_type
.as_nullable
599 if mtype
== null then mtype
= decltype
602 variable
.declared_type
= decltype
603 v
.set_variable
(self, variable
, mtype
)
605 #debug("var {variable}: {mtype}")
612 redef fun its_variable
do return self.variable
613 redef fun accept_typing
(v
)
615 var variable
= self.variable
616 if variable
== null then return # Skip error
618 var mtype
= v
.get_variable
(self, variable
)
619 if mtype
!= null then
620 #debug("{variable} is {mtype}")
622 #debug("{variable} is untyped")
629 redef class AVarAssignExpr
630 redef fun accept_typing
(v
)
632 var variable
= self.variable
633 assert variable
!= null
635 var mtype
= v
.visit_expr_subtype
(n_value
, variable
.declared_type
)
637 v
.set_variable
(self, variable
, mtype
)
643 redef class AReassignFormExpr
644 # The method designed by the reassign operator.
645 var reassign_callsite
: nullable CallSite
647 var read_type
: nullable MType = null
649 # Determine the `reassign_property`
650 # `readtype` is the type of the reading of the left value.
651 # `writetype` is the type of the writing of the left value.
652 # (Because of `ACallReassignExpr`, both can be different.
653 # Return the static type of the value to store.
654 private fun resolve_reassignment
(v
: TypeVisitor, readtype
, writetype
: MType): nullable MType
656 var reassign_name
: String
657 if self.n_assign_op
isa APlusAssignOp then
659 else if self.n_assign_op
isa AMinusAssignOp then
665 self.read_type
= readtype
667 if readtype
isa MNullType then
668 v
.error
(self, "Error: Method '{reassign_name}' call on 'null'.")
672 var callsite
= v
.get_method
(self, readtype
, reassign_name
, false)
673 if callsite
== null then return null # Skip error
674 self.reassign_callsite
= callsite
676 var msignature
= callsite
.msignature
677 var rettype
= msignature
.return_mtype
678 assert msignature
.arity
== 1 and rettype
!= null
680 var value_type
= v
.visit_expr_subtype
(self.n_value
, msignature
.mparameters
.first
.mtype
)
681 if value_type
== null then return null # Skip error
683 v
.check_subtype
(self, rettype
, writetype
)
688 redef class AVarReassignExpr
689 redef fun accept_typing
(v
)
691 var variable
= self.variable
692 assert variable
!= null
694 var readtype
= v
.get_variable
(self, variable
)
695 if readtype
== null then return
699 var writetype
= variable
.declared_type
700 if writetype
== null then return
702 var rettype
= self.resolve_reassignment
(v
, readtype
, writetype
)
704 v
.set_variable
(self, variable
, rettype
)
711 redef class AContinueExpr
712 redef fun accept_typing
(v
)
714 var nexpr
= self.n_expr
715 if nexpr
!= null then
716 var mtype
= v
.visit_expr
(nexpr
)
722 redef class ABreakExpr
723 redef fun accept_typing
(v
)
725 var nexpr
= self.n_expr
726 if nexpr
!= null then
727 var mtype
= v
.visit_expr
(nexpr
)
733 redef class AReturnExpr
734 redef fun accept_typing
(v
)
736 var nexpr
= self.n_expr
737 var ret_type
= v
.mpropdef
.as(MMethodDef).msignature
.return_mtype
738 if nexpr
!= null then
739 if ret_type
!= null then
740 var mtype
= v
.visit_expr_subtype
(nexpr
, ret_type
)
742 var mtype
= v
.visit_expr
(nexpr
)
743 v
.error
(self, "Error: Return with value in a procedure.")
745 else if ret_type
!= null then
746 v
.error
(self, "Error: Return without value in a function.")
752 redef class AAbortExpr
753 redef fun accept_typing
(v
)
760 redef fun accept_typing
(v
)
762 v
.visit_expr_bool
(n_expr
)
770 redef class AIfexprExpr
771 redef fun accept_typing
(v
)
773 v
.visit_expr_bool
(n_expr
)
775 var t1
= v
.visit_expr
(n_then
)
776 var t2
= v
.visit_expr
(n_else
)
778 if t1
== null or t2
== null then
782 var t
= v
.merge_types
(self, [t1
, t2
])
784 v
.error
(self, "Type Error: ambiguous type {t1} vs {t2}")
791 redef fun accept_typing
(v
)
793 v
.visit_stmt
(n_block
)
798 redef class AWhileExpr
799 redef fun accept_typing
(v
)
801 v
.visit_expr_bool
(n_expr
)
803 v
.visit_stmt
(n_block
)
808 redef class ALoopExpr
809 redef fun accept_typing
(v
)
811 v
.visit_stmt
(n_block
)
817 var coltype
: nullable MClassType
819 var method_iterator
: nullable MMethod
820 var method_is_ok
: nullable MMethod
821 var method_item
: nullable MMethod
822 var method_next
: nullable MMethod
823 var method_key
: nullable MMethod
825 private fun do_type_iterator
(v
: TypeVisitor, mtype
: MType)
827 if mtype
isa MNullType then
828 v
.error
(self, "Type error: 'for' cannot iterate over 'null'")
833 var objcla
= v
.get_mclass
(self, "Object")
834 if objcla
== null then return
836 # check iterator method
837 var unsafe_type
= v
.anchor_to
(mtype
)
838 if v
.try_get_mproperty_by_name2
(self, unsafe_type
, "iterator") == null then
839 if v
.try_get_mproperty_by_name2
(self, unsafe_type
, "iterate") == null then
840 v
.error
(self, "Type Error: 'for' expects a type providing 'iterator' method, got '{mtype}'.")
842 v
.modelbuilder
.error
(self, "NOT YET IMPLEMENTED: Do 'for' on {mtype}")
847 var itdef
= v
.get_method
(self, mtype
, "iterator", true)
848 if itdef
== null then
849 v
.error
(self, "Type Error: 'for' expects a type providing 'iterator' method, got '{mtype}'.")
852 self.method_iterator
= itdef
.mproperty
854 # check that iterator return something
855 var ittype
= itdef
.msignature
.return_mtype
856 if ittype
== null then
857 v
.error
(self, "Type Error: 'for' expects method 'iterator' to return an 'Iterator' or 'MapIterator' type'.")
862 var colit_cla
= v
.try_get_mclass
(self, "Iterator")
863 var mapit_cla
= v
.try_get_mclass
(self, "MapIterator")
867 if colit_cla
!= null and v
.is_subtype
(ittype
, colit_cla
.get_mtype
([objcla
.mclass_type
.as_nullable
])) then
869 var coltype
= ittype
.supertype_to
(v
.mmodule
, v
.anchor
, colit_cla
)
870 var variables
= self.variables
871 if variables
.length
!= 1 then
872 v
.error
(self, "Type Error: 'for' expects only one variable when using 'Iterator'.")
874 variables
.first
.declared_type
= coltype
.arguments
.first
879 if mapit_cla
!= null and v
.is_subtype
(ittype
, mapit_cla
.get_mtype
([objcla
.mclass_type
, objcla
.mclass_type
.as_nullable
])) then
881 var coltype
= ittype
.supertype_to
(v
.mmodule
, v
.anchor
, mapit_cla
)
882 var variables
= self.variables
883 if variables
.length
!= 2 then
884 v
.error
(self, "Type Error: 'for' expects two variables when using 'MapIterator'.")
886 variables
[0].declared_type
= coltype
.arguments
[0]
887 variables
[1].declared_type
= coltype
.arguments
[1]
892 if not is_col
and not is_map
then
893 v
.error
(self, "Type Error: 'for' expects method 'iterator' to return an 'Iterator' or 'MapIterator' type'.")
897 # anchor formal and virtual types
898 if mtype
.need_anchor
then mtype
= v
.anchor_to
(mtype
)
900 if mtype
isa MNullableType then mtype
= mtype
.mtype
901 self.coltype
= mtype
.as(MClassType)
903 # get methods is_ok, next, item
904 var ikdef
= v
.get_method
(self, ittype
, "is_ok", false)
905 if ikdef
== null then
906 v
.error
(self, "Type Error: 'for' expects a method 'is_ok' in 'Iterator' type {ittype}.")
909 self.method_is_ok
= ikdef
.mproperty
911 var itemdef
= v
.get_method
(self, ittype
, "item", false)
912 if itemdef
== null then
913 v
.error
(self, "Type Error: 'for' expects a method 'item' in 'Iterator' type {ittype}.")
916 self.method_item
= itemdef
.mproperty
918 var nextdef
= v
.get_method
(self, ittype
, "next", false)
919 if nextdef
== null then
920 v
.error
(self, "Type Error: 'for' expects a method 'next' in 'Iterator' type {ittype}.")
923 self.method_next
= nextdef
.mproperty
926 var keydef
= v
.get_method
(self, ittype
, "key", false)
927 if keydef
== null then
928 v
.error
(self, "Type Error: 'for' expects a method 'key' in 'Iterator' type {ittype}.")
931 self.method_key
= keydef
.mproperty
935 redef fun accept_typing
(v
)
937 var mtype
= v
.visit_expr
(n_expr
)
938 if mtype
== null then return
940 self.do_type_iterator
(v
, mtype
)
942 v
.visit_stmt
(n_block
)
947 redef class AAssertExpr
948 redef fun accept_typing
(v
)
950 v
.visit_expr_bool
(n_expr
)
958 redef fun accept_typing
(v
)
960 v
.visit_expr_bool
(n_expr
)
961 v
.visit_expr_bool
(n_expr2
)
962 self.mtype
= v
.type_bool
(self)
966 redef class AImpliesExpr
967 redef fun accept_typing
(v
)
969 v
.visit_expr_bool
(n_expr
)
970 v
.visit_expr_bool
(n_expr2
)
971 self.mtype
= v
.type_bool
(self)
976 redef fun accept_typing
(v
)
978 v
.visit_expr_bool
(n_expr
)
979 v
.visit_expr_bool
(n_expr2
)
980 self.mtype
= v
.type_bool
(self)
986 redef fun accept_typing
(v
)
988 v
.visit_expr_bool
(n_expr
)
989 self.mtype
= v
.type_bool
(self)
993 redef class AOrElseExpr
994 redef fun accept_typing
(v
)
996 var t1
= v
.visit_expr
(n_expr
)
997 var t2
= v
.visit_expr
(n_expr2
)
999 if t1
== null or t2
== null then
1003 if t1
isa MNullableType then
1007 var t
= v
.merge_types
(self, [t1
, t2
])
1009 t
= v
.mmodule
.object_type
1010 if t2
isa MNullableType then
1013 #v.error(self, "Type Error: ambiguous type {t1} vs {t2}")
1019 redef class ATrueExpr
1020 redef fun accept_typing
(v
)
1022 self.mtype
= v
.type_bool
(self)
1026 redef class AFalseExpr
1027 redef fun accept_typing
(v
)
1029 self.mtype
= v
.type_bool
(self)
1033 redef class AIntExpr
1034 redef fun accept_typing
(v
)
1036 var mclass
= v
.get_mclass
(self, "Int")
1037 if mclass
== null then return # Forward error
1038 self.mtype
= mclass
.mclass_type
1042 redef class AFloatExpr
1043 redef fun accept_typing
(v
)
1045 var mclass
= v
.get_mclass
(self, "Float")
1046 if mclass
== null then return # Forward error
1047 self.mtype
= mclass
.mclass_type
1051 redef class ACharExpr
1052 redef fun accept_typing
(v
)
1054 var mclass
= v
.get_mclass
(self, "Char")
1055 if mclass
== null then return # Forward error
1056 self.mtype
= mclass
.mclass_type
1060 redef class AStringFormExpr
1061 redef fun accept_typing
(v
)
1063 var mclass
= v
.get_mclass
(self, "String")
1064 if mclass
== null then return # Forward error
1065 self.mtype
= mclass
.mclass_type
1069 redef class ASuperstringExpr
1070 redef fun accept_typing
(v
)
1072 var mclass
= v
.get_mclass
(self, "String")
1073 if mclass
== null then return # Forward error
1074 self.mtype
= mclass
.mclass_type
1075 for nexpr
in self.n_exprs
do
1076 var t
= v
.visit_expr
(nexpr
)
1081 redef class AArrayExpr
1082 redef fun accept_typing
(v
)
1084 var mtypes
= new Array[nullable MType]
1085 for e
in self.n_exprs
.n_exprs
do
1086 var t
= v
.visit_expr
(e
)
1092 var mtype
= v
.merge_types
(self, mtypes
)
1093 if mtype
== null then
1094 v
.error
(self, "Type Error: ambiguous array type {mtypes.join(" ")}")
1097 var mclass
= v
.get_mclass
(self, "Array")
1098 if mclass
== null then return # Forward error
1099 self.mtype
= mclass
.get_mtype
([mtype
])
1103 redef class ARangeExpr
1104 redef fun accept_typing
(v
)
1106 var discrete_class
= v
.get_mclass
(self, "Discrete")
1107 if discrete_class
== null then return # Forward error
1108 var discrete_type
= discrete_class
.intro
.bound_mtype
1109 var t1
= v
.visit_expr_subtype
(self.n_expr
, discrete_type
)
1110 var t2
= v
.visit_expr_subtype
(self.n_expr2
, discrete_type
)
1111 if t1
== null or t2
== null then return
1112 var mclass
= v
.get_mclass
(self, "Range")
1113 if mclass
== null then return # Forward error
1114 if v
.is_subtype
(t1
, t2
) then
1115 self.mtype
= mclass
.get_mtype
([t2
])
1116 else if v
.is_subtype
(t2
, t1
) then
1117 self.mtype
= mclass
.get_mtype
([t1
])
1119 v
.error
(self, "Type Error: Cannot create range: {t1} vs {t2}")
1124 redef class ANullExpr
1125 redef fun accept_typing
(v
)
1127 self.mtype
= v
.mmodule
.model
.null_type
1131 redef class AIsaExpr
1132 # The static type to cast to.
1133 # (different from the static type of the expression that is `Bool`).
1134 var cast_type
: nullable MType
1135 redef fun accept_typing
(v
)
1137 var mtype
= v
.visit_expr_cast
(self, self.n_expr
, self.n_type
)
1138 self.cast_type
= mtype
1140 var variable
= self.n_expr
.its_variable
1141 if variable
!= null then
1142 var orig
= self.n_expr
.mtype
1143 var from
= if orig
!= null then orig
.to_s
else "invalid"
1144 var to
= if mtype
!= null then mtype
.to_s
else "invalid"
1145 #debug("adapt {variable}: {from} -> {to}")
1146 self.after_flow_context
.when_true
.set_var
(variable
, mtype
)
1149 self.mtype
= v
.type_bool
(self)
1153 redef class AAsCastExpr
1154 redef fun accept_typing
(v
)
1156 self.mtype
= v
.visit_expr_cast
(self, self.n_expr
, self.n_type
)
1160 redef class AAsNotnullExpr
1161 redef fun accept_typing
(v
)
1163 var mtype
= v
.visit_expr
(self.n_expr
)
1164 if mtype
isa MNullType then
1165 v
.error
(self, "Type error: as(not null) on null")
1168 if mtype
isa MNullableType then
1169 self.mtype
= mtype
.mtype
1172 # TODO: warn on useless as not null
1177 redef class AProxyExpr
1178 redef fun accept_typing
(v
)
1180 self.mtype
= v
.visit_expr
(self.n_expr
)
1184 redef class ASelfExpr
1185 redef var its_variable
: nullable Variable
1186 redef fun accept_typing
(v
)
1188 var variable
= v
.selfvariable
1189 self.its_variable
= variable
1190 self.mtype
= v
.get_variable
(self, variable
)
1194 ## MESSAGE SENDING AND PROPERTY
1196 redef class ASendExpr
1197 # The property invoked by the send.
1198 var callsite
: nullable CallSite
1200 redef fun accept_typing
(v
)
1202 var recvtype
= v
.visit_expr
(self.n_expr
)
1203 var name
= self.property_name
1205 if recvtype
== null then return # Forward error
1206 if recvtype
isa MNullType then
1207 v
.error
(self, "Error: Method '{name}' call on 'null'.")
1211 var callsite
= v
.get_method
(self, recvtype
, name
, self.n_expr
isa ASelfExpr)
1212 if callsite
== null then return
1213 self.callsite
= callsite
1214 var msignature
= callsite
.msignature
1216 var args
= compute_raw_arguments
1217 self.raw_arguments
= args
1219 callsite
.check_signature
(v
, args
)
1221 if callsite
.mproperty
.is_init
then
1222 var vmpropdef
= v
.mpropdef
1223 if not (vmpropdef
isa MMethodDef and vmpropdef
.mproperty
.is_init
) then
1224 v
.error
(self, "Can call a init only in another init")
1228 var ret
= msignature
.return_mtype
1232 self.is_typed
= true
1236 # The name of the property
1237 # Each subclass simply provide the correct name.
1238 private fun property_name
: String is abstract
1240 # An array of all arguments (excluding self)
1241 var raw_arguments
: nullable Array[AExpr]
1243 private fun compute_raw_arguments
: Array[AExpr] is abstract
1246 redef class ABinopExpr
1247 redef fun compute_raw_arguments
do return [n_expr2
]
1250 redef fun property_name
do return "=="
1251 redef fun accept_typing
(v
)
1255 var variable
= self.n_expr
.its_variable
1256 if variable
== null then return
1257 var mtype
= self.n_expr2
.mtype
1258 if not mtype
isa MNullType then return
1259 var vartype
= v
.get_variable
(self, variable
)
1260 if not vartype
isa MNullableType then return
1261 self.after_flow_context
.when_true
.set_var
(variable
, mtype
)
1262 self.after_flow_context
.when_false
.set_var
(variable
, vartype
.mtype
)
1263 #debug("adapt {variable}:{vartype} ; true->{mtype} false->{vartype.mtype}")
1267 redef fun property_name
do return "!="
1268 redef fun accept_typing
(v
)
1272 var variable
= self.n_expr
.its_variable
1273 if variable
== null then return
1274 var mtype
= self.n_expr2
.mtype
1275 if not mtype
isa MNullType then return
1276 var vartype
= v
.get_variable
(self, variable
)
1277 if not vartype
isa MNullableType then return
1278 self.after_flow_context
.when_false
.set_var
(variable
, mtype
)
1279 self.after_flow_context
.when_true
.set_var
(variable
, vartype
.mtype
)
1280 #debug("adapt {variable}:{vartype} ; true->{vartype.mtype} false->{mtype}")
1284 redef fun property_name
do return "<"
1287 redef fun property_name
do return "<="
1290 redef fun property_name
do return "<<"
1293 redef fun property_name
do return ">"
1296 redef fun property_name
do return ">="
1299 redef fun property_name
do return ">>"
1301 redef class APlusExpr
1302 redef fun property_name
do return "+"
1304 redef class AMinusExpr
1305 redef fun property_name
do return "-"
1307 redef class AStarshipExpr
1308 redef fun property_name
do return "<=>"
1310 redef class AStarExpr
1311 redef fun property_name
do return "*"
1313 redef class ASlashExpr
1314 redef fun property_name
do return "/"
1316 redef class APercentExpr
1317 redef fun property_name
do return "%"
1320 redef class AUminusExpr
1321 redef fun property_name
do return "unary -"
1322 redef fun compute_raw_arguments
do return new Array[AExpr]
1326 redef class ACallExpr
1327 redef fun property_name
do return n_id
.text
1328 redef fun compute_raw_arguments
do return n_args
.to_a
1331 redef class ACallAssignExpr
1332 redef fun property_name
do return n_id
.text
+ "="
1333 redef fun compute_raw_arguments
1335 var res
= n_args
.to_a
1341 redef class ABraExpr
1342 redef fun property_name
do return "[]"
1343 redef fun compute_raw_arguments
do return n_args
.to_a
1346 redef class ABraAssignExpr
1347 redef fun property_name
do return "[]="
1348 redef fun compute_raw_arguments
1350 var res
= n_args
.to_a
1356 redef class ASendReassignFormExpr
1357 # The property invoked for the writing
1358 var write_callsite
: nullable CallSite
1360 redef fun accept_typing
(v
)
1362 var recvtype
= v
.visit_expr
(self.n_expr
)
1363 var name
= self.property_name
1365 if recvtype
== null then return # Forward error
1366 if recvtype
isa MNullType then
1367 v
.error
(self, "Error: Method '{name}' call on 'null'.")
1371 var for_self
= self.n_expr
isa ASelfExpr
1372 var callsite
= v
.get_method
(self, recvtype
, name
, for_self
)
1374 if callsite
== null then return
1375 self.callsite
= callsite
1377 var args
= compute_raw_arguments
1378 self.raw_arguments
= args
1380 callsite
.check_signature
(v
, args
)
1382 var readtype
= callsite
.msignature
.return_mtype
1383 if readtype
== null then
1384 v
.error
(self, "Error: {name} is not a function")
1388 var wcallsite
= v
.get_method
(self, recvtype
, name
+ "=", self.n_expr
isa ASelfExpr)
1389 if wcallsite
== null then return
1390 self.write_callsite
= wcallsite
1392 var wtype
= self.resolve_reassignment
(v
, readtype
, wcallsite
.msignature
.mparameters
.last
.mtype
)
1393 if wtype
== null then return
1395 args
= args
.to_a
# duplicate so raw_arguments keeps only the getter args
1396 args
.add
(self.n_value
)
1397 wcallsite
.check_signature
(v
, args
)
1399 self.is_typed
= true
1403 redef class ACallReassignExpr
1404 redef fun property_name
do return n_id
.text
1405 redef fun compute_raw_arguments
do return n_args
.to_a
1408 redef class ABraReassignExpr
1409 redef fun property_name
do return "[]"
1410 redef fun compute_raw_arguments
do return n_args
.to_a
1413 redef class AInitExpr
1414 redef fun property_name
do return "init"
1415 redef fun compute_raw_arguments
do return n_args
.to_a
1419 fun to_a
: Array[AExpr] do return self.n_exprs
.to_a
1424 redef class ASuperExpr
1425 # The method to call if the super is in fact a 'super init call'
1426 # Note: if the super is a normal call-next-method, then this attribute is null
1427 var callsite
: nullable CallSite
1429 # The method to call is the super is a standard `call-next-method` super-call
1430 # Note: if the super is a special super-init-call, then this attribute is null
1431 var mpropdef
: nullable MMethodDef
1433 redef fun accept_typing
(v
)
1435 var recvtype
= v
.nclassdef
.mclassdef
.bound_mtype
1436 var mproperty
= v
.mpropdef
.mproperty
1437 if not mproperty
isa MMethod then
1438 v
.error
(self, "Error: super only usable in a method")
1441 var superprops
= mproperty
.lookup_super_definitions
(v
.mmodule
, recvtype
)
1442 if superprops
.length
== 0 then
1443 if mproperty
.is_init
and v
.mpropdef
.is_intro
then
1444 process_superinit
(v
)
1447 v
.error
(self, "Error: No super method to call for {mproperty}.")
1450 # FIXME: covariance of return type in linear extension?
1451 var superprop
= superprops
.first
1453 var msignature
= v
.resolve_signature_for
(superprop
, recvtype
, true)
1454 var args
= self.n_args
.to_a
1455 if args
.length
> 0 then
1456 v
.check_signature
(self, args
, mproperty
.name
, msignature
)
1458 self.mtype
= msignature
.return_mtype
1459 self.is_typed
= true
1460 v
.mpropdef
.has_supercall
= true
1461 mpropdef
= v
.mpropdef
.as(MMethodDef)
1464 private fun process_superinit
(v
: TypeVisitor)
1466 var recvtype
= v
.nclassdef
.mclassdef
.bound_mtype
1467 var mpropdef
= v
.mpropdef
1468 assert mpropdef
isa MMethodDef
1469 var mproperty
= mpropdef
.mproperty
1470 var superprop
: nullable MMethodDef = null
1471 for msupertype
in v
.nclassdef
.mclassdef
.supertypes
do
1472 msupertype
= msupertype
.anchor_to
(v
.mmodule
, recvtype
)
1473 var errcount
= v
.modelbuilder
.toolcontext
.error_count
1474 var candidate
= v
.try_get_mproperty_by_name2
(self, msupertype
, mproperty
.name
).as(nullable MMethod)
1475 if candidate
== null then
1476 if v
.modelbuilder
.toolcontext
.error_count
> errcount
then return # Forard error
1477 continue # Try next super-class
1479 if superprop
!= null and superprop
.mproperty
!= candidate
then
1480 v
.error
(self, "Error: conflicting super constructor to call for {mproperty}: {candidate.full_name}, {superprop.mproperty.full_name}")
1483 var candidatedefs
= candidate
.lookup_definitions
(v
.mmodule
, recvtype
)
1484 if superprop
!= null then
1485 if superprop
== candidatedefs
.first
then continue
1486 candidatedefs
.add
(superprop
)
1488 if candidatedefs
.length
> 1 then
1489 v
.error
(self, "Error: confliting property definitions for property {mproperty} in {recvtype}: {candidatedefs.join(", ")}")
1492 superprop
= candidatedefs
.first
1494 if superprop
== null then
1495 v
.error
(self, "Error: No super method to call for {mproperty}.")
1499 var msignature
= v
.resolve_signature_for
(superprop
, recvtype
, true)
1500 var callsite
= new CallSite(self, recvtype
, v
.mmodule
, v
.anchor
, true, superprop
.mproperty
, superprop
, msignature
, false)
1501 self.callsite
= callsite
1503 var args
= self.n_args
.to_a
1504 if args
.length
> 0 then
1505 callsite
.check_signature
(v
, args
)
1507 # Check there is at least enough parameters
1508 if mpropdef
.msignature
.arity
< msignature
.arity
then
1509 v
.error
(self, "Error: Not enough implicit arguments to pass. Got {mpropdef.msignature.arity}, expected at least {msignature.arity}. Signature is {msignature}")
1512 # Check that each needed parameter is conform
1514 for sp
in msignature
.mparameters
do
1515 var p
= mpropdef
.msignature
.mparameters
[i
]
1516 if not v
.is_subtype
(p
.mtype
, sp
.mtype
) then
1517 v
.error
(self, "Type error: expected argument #{i} of type {sp.mtype}, got implicit argument {p.name} of type {p.mtype}. Signature is {msignature}")
1524 self.is_typed
= true
1530 redef class ANewExpr
1531 # The constructor invoked by the new.
1532 var callsite
: nullable CallSite
1534 redef fun accept_typing
(v
)
1536 var recvtype
= v
.resolve_mtype
(self.n_type
)
1537 if recvtype
== null then return
1538 self.mtype
= recvtype
1540 if not recvtype
isa MClassType then
1541 if recvtype
isa MNullableType then
1542 v
.error
(self, "Type error: cannot instantiate the nullable type {recvtype}.")
1545 v
.error
(self, "Type error: cannot instantiate the formal type {recvtype}.")
1549 if recvtype
.mclass
.kind
== abstract_kind
then
1550 v
.error
(self, "Cannot instantiate abstract class {recvtype}.")
1552 else if recvtype
.mclass
.kind
== interface_kind
then
1553 v
.error
(self, "Cannot instantiate interface {recvtype}.")
1565 var callsite
= v
.get_method
(self, recvtype
, name
, false)
1566 if callsite
== null then return
1568 self.callsite
= callsite
1570 if not callsite
.mproperty
.is_init_for
(recvtype
.mclass
) then
1571 v
.error
(self, "Error: {name} is not a constructor.")
1575 var args
= n_args
.to_a
1576 callsite
.check_signature
(v
, args
)
1582 redef class AAttrFormExpr
1583 # The attribute acceded.
1584 var mproperty
: nullable MAttribute
1586 # The static type of the attribute.
1587 var attr_type
: nullable MType
1589 # Resolve the attribute acceded.
1590 private fun resolve_property
(v
: TypeVisitor)
1592 var recvtype
= v
.visit_expr
(self.n_expr
)
1593 if recvtype
== null then return # Skip error
1594 var name
= self.n_id
.text
1595 if recvtype
isa MNullType then
1596 v
.error
(self, "Error: Attribute '{name}' access on 'null'.")
1600 var unsafe_type
= v
.anchor_to
(recvtype
)
1601 var mproperty
= v
.try_get_mproperty_by_name2
(self, unsafe_type
, name
)
1602 if mproperty
== null then
1603 v
.modelbuilder
.error
(self, "Error: Attribute {name} doesn't exists in {recvtype}.")
1606 assert mproperty
isa MAttribute
1607 self.mproperty
= mproperty
1609 var mpropdefs
= mproperty
.lookup_definitions
(v
.mmodule
, unsafe_type
)
1610 assert mpropdefs
.length
== 1
1611 var mpropdef
= mpropdefs
.first
1612 var attr_type
= mpropdef
.static_mtype
.as(not null)
1613 attr_type
= v
.resolve_for
(attr_type
, recvtype
, self.n_expr
isa ASelfExpr)
1614 self.attr_type
= attr_type
1618 redef class AAttrExpr
1619 redef fun accept_typing
(v
)
1621 self.resolve_property
(v
)
1622 self.mtype
= self.attr_type
1627 redef class AAttrAssignExpr
1628 redef fun accept_typing
(v
)
1630 self.resolve_property
(v
)
1631 var mtype
= self.attr_type
1633 v
.visit_expr_subtype
(self.n_value
, mtype
)
1634 self.is_typed
= true
1638 redef class AAttrReassignExpr
1639 redef fun accept_typing
(v
)
1641 self.resolve_property
(v
)
1642 var mtype
= self.attr_type
1643 if mtype
== null then return # Skip error
1645 self.resolve_reassignment
(v
, mtype
, mtype
)
1647 self.is_typed
= true
1651 redef class AIssetAttrExpr
1652 redef fun accept_typing
(v
)
1654 self.resolve_property
(v
)
1655 var mtype
= self.attr_type
1656 if mtype
== null then return # Skip error
1658 var recvtype
= self.n_expr
.mtype
.as(not null)
1659 var bound
= v
.resolve_for
(mtype
, recvtype
, false)
1660 if bound
isa MNullableType then
1661 v
.error
(self, "Error: isset on a nullable attribute.")
1663 self.mtype
= v
.type_bool
(self)
1669 redef class ADebugTypeExpr
1670 redef fun accept_typing
(v
)
1672 var expr
= v
.visit_expr
(self.n_expr
)
1673 if expr
== null then return
1674 var unsafe
= v
.anchor_to
(expr
)
1675 var ntype
= self.n_type
1676 var mtype
= v
.resolve_mtype
(ntype
)
1677 if mtype
!= null and mtype
!= expr
then
1678 var umtype
= v
.anchor_to
(mtype
)
1679 v
.modelbuilder
.warning
(self, "Found type {expr} (-> {unsafe}), expected {mtype} (-> {umtype})")
1681 self.is_typed
= true