syntax: variable assignment can bypass cast
[nit.git] / src / syntax / typing.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2008 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 property bodies, statements and expressions
18 package typing
19
20 import syntax_base
21 import escape
22 import control_flow
23
24 redef class MMSrcModule
25 # Walk trough the module and type statments and expressions
26 # Require than supermodules are processed
27 meth do_typing(tc: ToolContext)
28 do
29 var tv = new TypingVisitor(tc, self)
30 tv.visit(node)
31 end
32 end
33
34 # Typing visitor
35 # * Associate local variables to nodes
36 # * Distinguish method call and local variable access
37 # * Resolve call and attribute access
38 # * Check type conformance
39 private class TypingVisitor
40 special AbsSyntaxVisitor
41 redef meth visit(n)
42 do
43 if n != null then n.accept_typing(self)
44 end
45
46 # Current knowledge about variables names and types
47 readable writable attr _variable_ctx: VariableContext
48
49 # Non-bypassable knowledge about variables names and types
50 readable writable attr _base_variable_ctx: VariableContext
51
52 # Current knowledge about escapable blocks
53 readable writable attr _escapable_ctx: EscapableContext = new EscapableContext(self)
54
55 # The current reciever
56 readable writable attr _self_var: ParamVariable
57
58 # Block of the current method
59 readable writable attr _top_block: PExpr
60
61 # List of explicit invocation of constructors of super-classes
62 readable writable attr _explicit_super_init_calls: Array[MMMethod]
63
64 # Is a other constructor of the same class invoked
65 readable writable attr _explicit_other_init_call: Bool
66
67 # Make the if_true_variable_ctx of the expression effective
68 private meth use_if_true_variable_ctx(e: PExpr)
69 do
70 var ctx = e.if_true_variable_ctx
71 if ctx != null then variable_ctx = ctx
72 end
73
74 # Make the if_false_variable_ctx of the expression effective
75 private meth use_if_false_variable_ctx(e: PExpr)
76 do
77 var ctx = e.if_false_variable_ctx
78 if ctx != null then variable_ctx = ctx
79 end
80
81 # Number of nested once
82 readable writable attr _once_count: Int = 0
83
84 init(tc, module) do super
85
86 private meth get_default_constructor_for(n: PNode, c: MMLocalClass, prop: MMSrcMethod): MMMethod
87 do
88 var v = self
89 #var prop = v.local_property
90 #assert prop isa MMMethod
91 var candidates = new Array[MMMethod]
92 var false_candidates = new Array[MMMethod]
93 var parity = prop.signature.arity
94 for g in c.global_properties do
95 if not g.is_init_for(c) then continue
96 var gp = c[g]
97 var gps = gp.signature_for(c.get_type)
98 assert gp isa MMSrcMethod
99 var garity = gps.arity
100 if prop != null and gp.name == prop.name then
101 if garity == 0 or (parity == garity and prop.signature < gps) then
102 return gp
103 else
104 false_candidates.add(gp)
105 end
106 else if garity == 0 and gp.name == once ("init".to_symbol) then
107 candidates.add(gp)
108 false_candidates.add(gp)
109 else
110 false_candidates.add(gp)
111 end
112 end
113 if candidates.length == 1 then
114 return candidates.first
115 else if candidates.length > 0 then
116 var a = new Array[String]
117 for p in candidates do
118 a.add("{p.full_name}{p.signature}")
119 end
120 v.error(n, "Error: Conflicting default constructor to call for {c}: {a.join(", ")}.")
121 return null
122 else if false_candidates.length > 0 then
123 var a = new Array[String]
124 for p in false_candidates do
125 a.add("{p.full_name}{p.signature}")
126 end
127 v.error(n, "Error: there is no available compatible constrctor in {c}. Discarded candidates are {a.join(", ")}.")
128 return null
129 else
130 v.error(n, "Error: there is no available compatible constrctor in {c}.")
131 return null
132 end
133 end
134 end
135
136
137 ###############################################################################
138
139 redef class PNode
140 private meth accept_typing(v: TypingVisitor)
141 do
142 accept_abs_syntax_visitor(v)
143 after_typing(v)
144 end
145 private meth after_typing(v: TypingVisitor) do end
146 end
147
148 redef class PClassdef
149 redef meth accept_typing(v)
150 do
151 v.self_var = new ParamVariable("self".to_symbol, self)
152 v.self_var.stype = local_class.get_type
153 super
154 end
155 end
156
157 redef class AAttrPropdef
158 redef meth accept_typing(v)
159 do
160 super
161 if n_expr != null then
162 v.check_conform_expr(n_expr, prop.signature.return_type)
163 end
164 end
165 end
166
167 redef class AMethPropdef
168 redef readable attr _self_var: ParamVariable
169 redef meth accept_typing(v)
170 do
171 v.variable_ctx = new RootVariableContext(v, self)
172 v.base_variable_ctx = v.variable_ctx
173 _self_var = v.self_var
174 super
175 end
176 end
177
178 redef class AConcreteMethPropdef
179 redef meth accept_typing(v)
180 do
181 super
182 if v.variable_ctx.unreash == false and method.signature.return_type != null then
183 v.error(self, "Control error: Reached end of function (a 'return' with a value was expected).")
184 end
185 end
186 end
187
188 redef class AConcreteInitPropdef
189 readable attr _super_init_calls: Array[MMMethod] = new Array[MMMethod]
190 readable attr _explicit_super_init_calls: Array[MMMethod] = new Array[MMMethod]
191 redef meth accept_typing(v)
192 do
193 v.top_block = n_block
194 v.explicit_super_init_calls = explicit_super_init_calls
195 v.explicit_other_init_call = false
196 super
197 if v.explicit_other_init_call or method.global.intro != method then
198 # TODO: something?
199 else
200 var i = 0
201 var l = explicit_super_init_calls.length
202 var cur_m: MMMethod = null
203 var cur_c: MMLocalClass = null
204 if i < l then
205 cur_m = explicit_super_init_calls[i]
206 cur_c = cur_m.global.intro.local_class.for_module(v.module)
207 end
208 var j = 0
209 while j < v.local_class.cshe.direct_greaters.length do
210 var c = v.local_class.cshe.direct_greaters[j]
211 if c.global.is_interface or c.global.is_universal or c.global.is_mixin then
212 j += 1
213 else if cur_c != null and (c.cshe <= cur_c or cur_c.global.is_mixin) then
214 if c == cur_c then j += 1
215 super_init_calls.add(cur_m)
216 i += 1
217 if i < l then
218 cur_m = explicit_super_init_calls[i]
219 cur_c = cur_m.global.intro.local_class.for_module(v.module)
220 else
221 cur_m = null
222 cur_c = null
223 end
224 else
225 var p = v.get_default_constructor_for(self, c, method)
226 if p != null then
227 super_init_calls.add(p)
228 end
229 j += 1
230 end
231 end
232 end
233 end
234 end
235
236 redef class PParam
237 redef meth after_typing(v)
238 do
239 # TODO: why the test?
240 if v.variable_ctx != null then
241 v.variable_ctx.add(variable)
242 end
243 end
244 end
245
246 redef class AClosureDecl
247 # The corresponding escapable object
248 readable attr _escapable: EscapableBlock
249
250 redef meth accept_typing(v)
251 do
252 # Register the closure for ClosureCallExpr
253 v.variable_ctx.add(variable)
254
255 var old_var_ctx = v.variable_ctx
256 var old_base_var_ctx = v.base_variable_ctx
257 v.base_variable_ctx = v.variable_ctx
258 v.variable_ctx = v.variable_ctx.sub(self)
259
260 _escapable = new EscapableClosure(self, variable.closure, null)
261 v.escapable_ctx.push(_escapable)
262
263 super
264
265 if n_expr != null then
266 if v.variable_ctx.unreash == false then
267 if variable.closure.signature.return_type != null then
268 v.error(self, "Control error: Reached end of block (a 'continue' with a value was expected).")
269 else if variable.closure.is_break then
270 v.error(self, "Control error: Reached end of break block (an 'abort' was expected).")
271 end
272 end
273 end
274
275 old_var_ctx.merge(v.variable_ctx)
276 v.variable_ctx = old_var_ctx
277 v.base_variable_ctx = old_base_var_ctx
278 v.escapable_ctx.pop
279 end
280 end
281
282 redef class PType
283 readable attr _stype: MMType
284 redef meth after_typing(v)
285 do
286 _stype = get_stype(v)
287 end
288 end
289
290 redef class PExpr
291 redef readable attr _is_typed: Bool = false
292 redef meth is_statement: Bool do return _stype == null
293 redef meth stype
294 do
295 if not is_typed then
296 print "{locate}: not is_typed"
297 abort
298 end
299 if is_statement then
300 print "{locate}: is_statement"
301 abort
302 end
303 return _stype
304 end
305 attr _stype: MMType
306
307 # Is the expression the implicit receiver
308 meth is_implicit_self: Bool do return false
309
310 # Is the expression the current receiver (implicit or explicit)
311 meth is_self: Bool do return false
312
313 # The variable accessed is any
314 meth its_variable: Variable do return null
315
316 # The variable type information if current boolean expression is true
317 readable private attr _if_true_variable_ctx: VariableContext
318
319 # The variable type information if current boolean expression is false
320 readable private attr _if_false_variable_ctx: VariableContext
321 end
322
323 redef class AVardeclExpr
324 redef meth after_typing(v)
325 do
326 var va = new VarVariable(n_id.to_symbol, self)
327 variable = va
328 v.variable_ctx.add(va)
329 if n_expr != null then v.variable_ctx.mark_is_set(va)
330
331 if n_type != null then
332 va.stype = n_type.stype
333 if n_expr != null then
334 v.check_conform_expr(n_expr, va.stype)
335 end
336 else
337 if not v.check_expr(n_expr) then return
338 va.stype = n_expr.stype
339 end
340 _is_typed = true
341 end
342 end
343
344 redef class ABlockExpr
345 redef meth accept_typing(v)
346 do
347 var old_var_ctx = v.variable_ctx
348 v.variable_ctx = v.variable_ctx.sub(self)
349
350 for e in n_expr do
351 if v.variable_ctx.unreash and not v.variable_ctx.already_unreash then
352 v.variable_ctx.already_unreash = true
353 v.warning(e, "Warning: unreachable statement.")
354 end
355 v.visit(e)
356 end
357
358 old_var_ctx.merge(v.variable_ctx)
359 v.variable_ctx = old_var_ctx
360 _is_typed = true
361 end
362 end
363
364 redef class AReturnExpr
365 redef meth after_typing(v)
366 do
367 v.variable_ctx.unreash = true
368 var t = v.local_property.signature.return_type
369 if n_expr == null and t != null then
370 v.error(self, "Error: Return without value in a function.")
371 else if n_expr != null and t == null then
372 v.error(self, "Error: Return with value in a procedure.")
373 else if n_expr != null and t != null then
374 v.check_conform_expr(n_expr, t)
375 end
376 _is_typed = true
377 end
378 end
379
380 redef class AContinueExpr
381 redef meth after_typing(v)
382 do
383 v.variable_ctx.unreash = true
384 var esc = compute_escapable_block(v.escapable_ctx)
385 if esc == null then return
386
387 if esc.is_break_block then
388 v.error(self, "Error: 'continue' forbiden in break blocks.")
389 return
390 end
391
392 var t = esc.continue_stype
393 if n_expr == null and t != null then
394 v.error(self, "Error: continue with a value required in this block.")
395 else if n_expr != null and t == null then
396 v.error(self, "Error: continue without value required in this block.")
397 else if n_expr != null and t != null then
398 v.check_conform_expr(n_expr, t)
399 end
400 _is_typed = true
401 end
402 end
403
404 redef class ABreakExpr
405 redef meth after_typing(v)
406 do
407 v.variable_ctx.unreash = true
408 var esc = compute_escapable_block(v.escapable_ctx)
409 if esc == null then return
410
411 var bl = esc.break_list
412 if n_expr == null and bl != null then
413 v.error(self, "Error: break with a value required in this block.")
414 else if n_expr != null and bl == null then
415 v.error(self, "Error: break without value required in this block.")
416 else if n_expr != null and bl != null then
417 # Typing check can only be done later
418 bl.add(n_expr)
419 end
420 _is_typed = true
421 end
422 end
423
424 redef class AAbortExpr
425 redef meth after_typing(v)
426 do
427 v.variable_ctx.unreash = true
428 end
429 end
430
431 redef class AIfExpr
432 redef meth accept_typing(v)
433 do
434 var old_var_ctx = v.variable_ctx
435 v.visit(n_expr)
436 v.check_conform_expr(n_expr, v.type_bool)
437
438 # Prepare 'then' context
439 v.use_if_true_variable_ctx(n_expr)
440
441 # Process the 'then'
442 if n_then != null then
443 v.variable_ctx = v.variable_ctx.sub(n_then)
444 v.visit(n_then)
445 end
446
447 # Remember what appened in the 'then'
448 var then_var_ctx = v.variable_ctx
449
450 # Prepare 'else' context
451 v.variable_ctx = old_var_ctx
452 v.use_if_false_variable_ctx(n_expr)
453
454 # Process the 'else'
455 if n_else != null then
456 v.variable_ctx = v.variable_ctx.sub(n_else)
457 v.visit(n_else)
458 end
459
460 # Merge 'then' and 'else' contexts
461 old_var_ctx.merge2(then_var_ctx, v.variable_ctx, v.base_variable_ctx)
462 v.variable_ctx = old_var_ctx
463 _is_typed = true
464 end
465 end
466
467 redef class AWhileExpr
468 # The corresponding escapable block
469 readable attr _escapable: EscapableBlock
470
471 redef meth accept_typing(v)
472 do
473 _escapable = new EscapableBlock(self)
474 v.escapable_ctx.push(_escapable)
475 var old_var_ctx = v.variable_ctx
476 var old_base_var_ctx = v.base_variable_ctx
477 v.base_variable_ctx = v.variable_ctx
478 v.variable_ctx = v.variable_ctx.sub(self)
479
480 super
481
482 v.check_conform_expr(n_expr, v.type_bool)
483 v.variable_ctx = old_var_ctx
484 v.base_variable_ctx = old_base_var_ctx
485 v.escapable_ctx.pop
486 _is_typed = true
487 end
488 end
489
490 redef class AForExpr
491 # The corresponding escapable block
492 readable attr _escapable: EscapableBlock
493
494 readable attr _meth_iterator: MMMethod
495 readable attr _meth_is_ok: MMMethod
496 readable attr _meth_item: MMMethod
497 readable attr _meth_next: MMMethod
498 redef meth accept_typing(v)
499 do
500 _escapable = new EscapableBlock(self)
501 v.escapable_ctx.push(_escapable)
502
503 var old_var_ctx = v.variable_ctx
504 var old_base_var_ctx = v.base_variable_ctx
505 v.base_variable_ctx = v.variable_ctx
506 v.variable_ctx = v.variable_ctx.sub(self)
507 var va = new AutoVariable(n_id.to_symbol, self)
508 variable = va
509 v.variable_ctx.add(va)
510
511 v.visit(n_expr)
512
513 if not v.check_conform_expr(n_expr, v.type_collection) then return
514 var expr_type = n_expr.stype
515 _meth_iterator = expr_type.local_class.select_method(once ("iterator".to_symbol))
516 if _meth_iterator == null then
517 v.error(self, "Error: Collection MUST have an iterate method")
518 return
519 end
520 var iter_type = _meth_iterator.signature_for(expr_type).return_type
521 _meth_is_ok = iter_type.local_class.select_method(once ("is_ok".to_symbol))
522 if _meth_is_ok == null then
523 v.error(self, "Error: {iter_type} MUST have an is_ok method")
524 return
525 end
526 _meth_item = iter_type.local_class.select_method(once ("item".to_symbol))
527 if _meth_item == null then
528 v.error(self, "Error: {iter_type} MUST have an item method")
529 return
530 end
531 _meth_next = iter_type.local_class.select_method(once ("next".to_symbol))
532 if _meth_next == null then
533 v.error(self, "Error: {iter_type} MUST have a next method")
534 return
535 end
536 var t = _meth_item.signature_for(iter_type).return_type
537 if not n_expr.is_self then t = t.not_for_self
538 va.stype = t
539
540 if n_block != null then v.visit(n_block)
541
542 # pop context
543 v.variable_ctx = old_var_ctx
544 v.base_variable_ctx = old_base_var_ctx
545 v.escapable_ctx.pop
546 _is_typed = true
547 end
548 end
549
550 redef class AAssertExpr
551 redef meth after_typing(v)
552 do
553 v.check_conform_expr(n_expr, v.type_bool)
554 v.use_if_true_variable_ctx(n_expr)
555 _is_typed = true
556 end
557 end
558
559 redef class AVarExpr
560 redef meth its_variable do return variable
561
562 redef meth after_typing(v)
563 do
564 v.variable_ctx.check_is_set(self, variable)
565 _stype = v.variable_ctx.stype(variable)
566 _is_typed = _stype != null
567 end
568 end
569
570 redef class AVarAssignExpr
571 redef meth after_typing(v)
572 do
573 v.variable_ctx.mark_is_set(variable)
574 var t = v.variable_ctx.stype(variable)
575
576 # Check the base type
577 var btype = v.base_variable_ctx.stype(variable)
578 if not v.check_conform_expr(n_value, btype) then return
579
580 # Bypasse cast if then current type does not match
581 if not n_value.stype < t then v.variable_ctx.stype(variable) = btype
582
583 _is_typed = true
584 end
585 end
586
587 redef class AReassignFormExpr
588 # Compute and check method used through the reassigment operator
589 # On success return the static type of the result of the reassigment operator
590 # Else display an error and return null
591 private meth do_rvalue_typing(v: TypingVisitor, type_lvalue: MMType): MMType
592 do
593 if type_lvalue == null then
594 return null
595 end
596 var name = n_assign_op.method_name
597 var lc = type_lvalue.local_class
598 if not lc.has_global_property_by_name(name) then
599 v.error(self, "Error: Method '{name}' doesn't exists in {type_lvalue}.")
600 return null
601 end
602 var prop = lc.select_method(name)
603 prop.global.check_visibility(v, self, v.module, false)
604 var psig = prop.signature_for(type_lvalue)
605 _assign_method = prop
606 if not v.check_conform_expr(n_value, psig[0].not_for_self) then return null
607 return psig.return_type.not_for_self
608 end
609
610 # Method used through the reassigment operator (once computed)
611 readable attr _assign_method: MMMethod
612 end
613
614 redef class AVarReassignExpr
615 redef meth after_typing(v)
616 do
617 v.variable_ctx.check_is_set(self, variable)
618 v.variable_ctx.mark_is_set(variable)
619 var t = v.variable_ctx.stype(variable)
620 var t2 = do_rvalue_typing(v, t)
621 if t2 == null then return
622
623 # Check the base type
624 var btype = v.base_variable_ctx.stype(variable)
625 if not v.check_conform(n_value, t2, btype) then return
626
627 # Bypasse cast if then current type does not match
628 if not t2 < t then v.variable_ctx.stype(variable) = btype
629
630 _is_typed = true
631 end
632 end
633
634 redef class PAssignOp
635 meth method_name: Symbol is abstract
636 end
637 redef class APlusAssignOp
638 redef meth method_name do return once "+".to_symbol
639 end
640 redef class AMinusAssignOp
641 redef meth method_name do return once "-".to_symbol
642 end
643
644 redef class ASelfExpr
645 redef meth its_variable do return variable
646
647 redef meth after_typing(v)
648 do
649 variable = v.self_var
650 _stype = v.variable_ctx.stype(variable)
651 _is_typed = true
652 end
653
654 redef meth is_self do return true
655 end
656
657 redef class AImplicitSelfExpr
658 redef meth is_implicit_self do return true
659 end
660
661 redef class AIfexprExpr
662 redef meth accept_typing(v)
663 do
664 var old_var_ctx = v.variable_ctx
665
666 v.visit(n_expr)
667 v.use_if_true_variable_ctx(n_expr)
668 v.visit(n_then)
669 v.variable_ctx = old_var_ctx
670 v.use_if_false_variable_ctx(n_expr)
671 v.visit(n_else)
672
673 v.check_conform_expr(n_expr, v.type_bool)
674
675 _stype = v.check_conform_multiexpr(null, [n_then, n_else])
676 _is_typed = _stype != null
677 end
678 end
679
680 redef class ABoolExpr
681 redef meth after_typing(v)
682 do
683 _stype = v.type_bool
684 _is_typed = true
685 end
686 end
687
688 redef class AOrExpr
689 redef meth after_typing(v)
690 do
691 var old_var_ctx = v.variable_ctx
692
693 v.visit(n_expr)
694 v.use_if_false_variable_ctx(n_expr)
695
696 v.visit(n_expr2)
697 if n_expr2.if_false_variable_ctx != null then
698 _if_false_variable_ctx = n_expr2.if_false_variable_ctx
699 else
700 _if_false_variable_ctx = v.variable_ctx
701 end
702
703 v.variable_ctx = old_var_ctx
704
705 v.check_conform_expr(n_expr, v.type_bool)
706 v.check_conform_expr(n_expr2, v.type_bool)
707 _stype = v.type_bool
708 _is_typed = true
709 end
710 end
711
712 redef class AAndExpr
713 redef meth accept_typing(v)
714 do
715 var old_var_ctx = v.variable_ctx
716
717 v.visit(n_expr)
718 v.use_if_true_variable_ctx(n_expr)
719
720 v.visit(n_expr2)
721 if n_expr2.if_true_variable_ctx != null then
722 _if_true_variable_ctx = n_expr2.if_true_variable_ctx
723 else
724 _if_true_variable_ctx = v.variable_ctx
725 end
726
727 v.variable_ctx = old_var_ctx
728
729 v.check_conform_expr(n_expr, v.type_bool)
730 v.check_conform_expr(n_expr2, v.type_bool)
731 _stype = v.type_bool
732 _is_typed = true
733 end
734 end
735
736 redef class ANotExpr
737 redef meth after_typing(v)
738 do
739 v.check_conform_expr(n_expr, v.type_bool)
740
741 # Invert if_true/if_false information
742 _if_false_variable_ctx = n_expr._if_true_variable_ctx
743 _if_true_variable_ctx = n_expr._if_false_variable_ctx
744
745 _stype = v.type_bool
746 _is_typed = true
747 end
748 end
749
750 redef class AIntExpr
751 redef meth after_typing(v)
752 do
753 _stype = v.type_int
754 _is_typed = true
755 end
756 end
757
758 redef class AFloatExpr
759 redef meth after_typing(v)
760 do
761 _stype = v.type_float
762 _is_typed = true
763 end
764 end
765
766 redef class ACharExpr
767 redef meth after_typing(v)
768 do
769 _stype = v.type_char
770 _is_typed = true
771 end
772 end
773
774 redef class AStringFormExpr
775 readable attr _meth_with_native: MMMethod
776 redef meth after_typing(v)
777 do
778 _stype = v.type_string
779 _is_typed = true
780 _meth_with_native = _stype.local_class.select_method(once "with_native".to_symbol)
781 if _meth_with_native == null then v.error(self, "{_stype} MUST have a with_native method.")
782 end
783 end
784
785 redef class ASuperstringExpr
786 readable attr _meth_with_capacity: MMMethod
787 readable attr _meth_add: MMMethod
788 readable attr _meth_to_s: MMMethod
789 readable attr _atype: MMType
790 redef meth after_typing(v)
791 do
792 _stype = v.type_string
793 _atype = v.type_array(_stype)
794 _meth_with_capacity = _atype.local_class.select_method(once "with_capacity".to_symbol)
795 if _meth_with_capacity == null then v.error(self, "{_atype} MUST have a with_capacity method.")
796 _meth_add = _atype.local_class.select_method(once "add".to_symbol)
797 if _meth_add == null then v.error(self, "{_atype} MUST have an add method.")
798 _meth_to_s = v.type_object.local_class.select_method(once "to_s".to_symbol)
799 if _meth_to_s == null then v.error(self, "Object MUST have a to_s method.")
800 _is_typed = true
801 end
802 end
803
804 redef class ANullExpr
805 redef meth after_typing(v)
806 do
807 _stype = v.type_none
808 _is_typed = true
809 end
810 end
811
812 redef class AArrayExpr
813 readable attr _meth_with_capacity: MMMethod
814 readable attr _meth_add: MMMethod
815
816 redef meth after_typing(v)
817 do
818 var stype = v.check_conform_multiexpr(null, n_exprs)
819 if stype == null then return
820 do_typing(v, stype)
821 end
822
823 private meth do_typing(v: TypingVisitor, element_type: MMType)
824 do
825 _stype = v.type_array(element_type)
826
827 _meth_with_capacity = _stype.local_class.select_method(once "with_capacity".to_symbol)
828 if _meth_with_capacity == null then v.error(self, "{_stype} MUST have a with_capacity method.")
829 _meth_add = _stype.local_class.select_method(once "add".to_symbol)
830 if _meth_add == null then v.error(self, "{_stype} MUST have an add method.")
831
832 _is_typed = true
833 end
834 end
835
836 redef class ARangeExpr
837 readable attr _meth_init: MMMethod
838 redef meth after_typing(v)
839 do
840 if not v.check_expr(n_expr) or not v.check_expr(n_expr2) then return
841 var ntype = n_expr.stype
842 var ntype2 = n_expr2.stype
843 if ntype < ntype2 then
844 ntype = ntype2
845 else if not ntype2 < ntype then
846 v.error(self, "Type error: {ntype} incompatible with {ntype2}.")
847 return
848 end
849 var dtype = v.type_discrete
850 if not v.check_conform_expr(n_expr, dtype) or not v.check_conform_expr(n_expr2, dtype) then return
851 _stype = v.type_range(ntype)
852 _is_typed = true
853 end
854 end
855
856 redef class ACrangeExpr
857 redef meth after_typing(v)
858 do
859 super
860 _meth_init = stype.local_class.select_method(once "init".to_symbol)
861 end
862 end
863 redef class AOrangeExpr
864 redef meth after_typing(v)
865 do
866 super
867 _meth_init = stype.local_class.select_method(once "without_last".to_symbol)
868 end
869 end
870
871
872 redef class ASuperExpr
873 special ASuperInitCall
874 # readable attr _prop: MMSrcMethod
875 readable attr _init_in_superclass: MMMethod
876 redef meth after_typing(v)
877 do
878 var precs: Array[MMLocalProperty] = v.local_property.prhe.direct_greaters
879 if not precs.is_empty then
880 v.local_property.need_super = true
881 else if v.local_property.global.is_init then
882 var base_precs = v.local_class.super_methods_named(v.local_property.name)
883 for p in base_precs do
884 if not p.global.is_init then
885 v.error(self, "Error: {p.local_class}::{p} is not a constructor.")
886 else
887 precs.add(v.local_class[p.global])
888 end
889 end
890 if precs.is_empty then
891 v.error(self, "Error: No contructor named {v.local_property.name} in superclasses.")
892 return
893 else if precs.length > 1 then
894 v.error(self, "Error: Conflicting contructors named {v.local_property.name} in superclasses: {precs.join(", ")}.")
895 return
896 end
897 var p = base_precs.first
898 assert p isa MMMethod
899 _init_in_superclass = p
900 register_super_init_call(v, p)
901 if n_args.length > 0 then
902 var signature = get_signature(v, v.self_var.stype, p, true)
903 _arguments = process_signature(v, signature, p.name, n_args.to_a)
904 end
905 else
906 v.error(self, "Error: No super method to call for {v.local_property}.")
907 return
908 end
909
910 if precs.first.signature_for(v.self_var.stype).return_type != null then
911 var stypes = new Array[MMType]
912 var stype: MMType = null
913 for prop in precs do
914 assert prop isa MMMethod
915 var t = prop.signature_for(v.self_var.stype).return_type.for_module(v.module).adapt_to(v.local_property.signature.recv)
916 stypes.add(t)
917 if stype == null or stype < t then
918 stype = t
919 end
920 end
921 for t in stypes do
922 v.check_conform(self, t, stype)
923 end
924 _stype = stype
925 end
926 var p = v.local_property
927 assert p isa MMSrcMethod
928 _prop = p
929 _is_typed = true
930 end
931 end
932
933 redef class AAttrFormExpr
934 # Attribute accessed
935 readable attr _prop: MMAttribute
936
937 # Attribute type of the acceded attribute
938 readable attr _attr_type: MMType
939
940 # Compute the attribute accessed
941 private meth do_typing(v: TypingVisitor)
942 do
943 if not v.check_expr(n_expr) then return
944 var type_recv = n_expr.stype
945 var name = n_id.to_symbol
946 var lc = type_recv.local_class
947 if not lc.has_global_property_by_name(name) then
948 v.error(self, "Error: Attribute {name} doesn't exists in {type_recv}.")
949 return
950 end
951 var prop = lc.select_attribute(name)
952 if v.module.visibility_for(prop.global.local_class.module) < 3 then
953 v.error(self, "Error: Attribute {name} from {prop.global.local_class.module} is invisible in {v.module}")
954 end
955 _prop = prop
956 var at = prop.signature_for(type_recv).return_type
957 if not n_expr.is_self then at = at.not_for_self
958 _attr_type = at
959 end
960 end
961
962 redef class AAttrExpr
963 redef meth after_typing(v)
964 do
965 do_typing(v)
966 if prop == null then return
967 _stype = attr_type
968 _is_typed = true
969 end
970 end
971
972 redef class AAttrAssignExpr
973 redef meth after_typing(v)
974 do
975 do_typing(v)
976 if prop == null then return
977 if not v.check_conform_expr(n_value, attr_type) then return
978 _is_typed = true
979 end
980 end
981
982 redef class AAttrReassignExpr
983 redef meth after_typing(v)
984 do
985 do_typing(v)
986 if prop == null then return
987 var t = do_rvalue_typing(v, attr_type)
988 if t == null then return
989 v.check_conform(self, t, n_value.stype)
990 _is_typed = true
991 end
992 end
993
994 class AAbsAbsSendExpr
995 special PExpr
996 # The signature of the called property
997 readable attr _prop_signature: MMSignature
998
999 # The real arguments used (after star transformation) (once computed)
1000 readable attr _arguments: Array[PExpr]
1001
1002 # Check the conformity of a set of arguments `raw_args' to a signature.
1003 private meth process_signature(v: TypingVisitor, psig: MMSignature, name: Symbol, raw_args: Array[PExpr]): Array[PExpr]
1004 do
1005 var par_vararg = psig.vararg_rank
1006 var par_arity = psig.arity
1007 var raw_arity: Int
1008 if raw_args == null then raw_arity = 0 else raw_arity = raw_args.length
1009 if par_arity > raw_arity or (par_arity != raw_arity and par_vararg == -1) then
1010 v.error(self, "Error: '{name}' arity missmatch.")
1011 return null
1012 end
1013 var arg_idx = 0
1014 var args = new Array[PExpr]
1015 for par_idx in [0..par_arity[ do
1016 var a: PExpr
1017 var par_type = psig[par_idx]
1018 if par_idx == par_vararg then
1019 var star = new Array[PExpr]
1020 for i in [0..(raw_arity-par_arity)] do
1021 a = raw_args[arg_idx]
1022 v.check_conform_expr(a, par_type)
1023 star.add(a)
1024 arg_idx = arg_idx + 1
1025 end
1026 var aa = new AArrayExpr.init_aarrayexpr(star)
1027 aa.do_typing(v, par_type)
1028 a = aa
1029 else
1030 a = raw_args[arg_idx]
1031 v.check_conform_expr(a, par_type)
1032 arg_idx = arg_idx + 1
1033 end
1034 args.add(a)
1035 end
1036 return args
1037 end
1038
1039 # Check the conformity of a set of defined closures
1040 private meth process_closures(v: TypingVisitor, psig: MMSignature, name: Symbol, cd: Array[PClosureDef]): MMType
1041 do
1042 var t = psig.return_type
1043 var cs = psig.closures # Declared closures
1044 var min_arity = 0
1045 for c in cs do
1046 if not c.is_optional then min_arity += 1
1047 end
1048 if cd != null then
1049 if cs.length == 0 then
1050 v.error(self, "Error: {name} does not require blocks.")
1051 else if cd.length > cs.length or cd.length < min_arity then
1052 v.error(self, "Error: {name} requires {cs.length} blocks, {cd.length} found.")
1053 else
1054 # Initialize the break list if a value is required for breaks (ie. if the method is a function)
1055 var break_list: Array[ABreakExpr] = null
1056 if t != null then break_list = new Array[ABreakExpr]
1057
1058 # Process each closure definition
1059 for i in [0..cd.length[ do
1060 var csi = cs[i]
1061 var cdi = cd[i]
1062 var esc = new EscapableClosure(cdi, csi, break_list)
1063 v.escapable_ctx.push(esc)
1064 cdi.accept_typing2(v, esc)
1065 v.escapable_ctx.pop
1066 end
1067
1068 # Check break type conformity
1069 if break_list != null then
1070 t = v.check_conform_multiexpr(t, break_list)
1071 end
1072 end
1073 else if min_arity != 0 then
1074 v.error(self, "Error: {name} requires {cs.length} blocks.")
1075 end
1076 return t
1077 end
1078 end
1079
1080 class AAbsSendExpr
1081 special AAbsAbsSendExpr
1082 # Compute the called global property
1083 private meth do_typing(v: TypingVisitor, type_recv: MMType, is_implicit_self: Bool, recv_is_self: Bool, name: Symbol, raw_args: Array[PExpr], closure_defs: Array[PClosureDef])
1084 do
1085 var prop = get_property(v, type_recv, is_implicit_self, name)
1086 if prop == null then return
1087 var sig = get_signature(v, type_recv, prop, recv_is_self)
1088 if sig == null then return
1089 var args = process_signature(v, sig, prop.name, raw_args)
1090 if args == null then return
1091 var rtype = process_closures(v, sig, prop.name, closure_defs)
1092 if rtype == null and sig.return_type != null then return
1093 _prop = prop
1094 _prop_signature = sig
1095 _arguments = args
1096 _return_type = rtype
1097 end
1098
1099 private meth get_property(v: TypingVisitor, type_recv: MMType, is_implicit_self: Bool, name: Symbol): MMMethod
1100 do
1101 if type_recv == null then return null
1102 var lc = type_recv.local_class
1103 var prop: MMMethod = null
1104 if lc.has_global_property_by_name(name) then prop = lc.select_method(name)
1105 if prop == null and v.local_property.global.is_init then
1106 var props = type_recv.local_class.super_methods_named(name)
1107 if props.length > 1 then
1108 v.error(self, "Error: Ambigous method name '{name}' for {props.join(", ")}. Use explicit designation.")
1109 return null
1110 else if props.length == 1 then
1111 var p = type_recv.local_class[props.first.global]
1112 assert p isa MMMethod
1113 prop = p
1114 end
1115
1116 end
1117 if prop == null then
1118 if is_implicit_self then
1119 v.error(self, "Error: Method or variable '{name}' unknown in {type_recv}.")
1120 else
1121 v.error(self, "Error: Method '{name}' doesn't exists in {type_recv}.")
1122 end
1123 return null
1124 end
1125 return prop
1126 end
1127
1128 # Get the signature for a local property and a receiver
1129 private meth get_signature(v: TypingVisitor, type_recv: MMType, prop: MMMethod, recv_is_self: Bool): MMSignature
1130 do
1131 prop.global.check_visibility(v, self, v.module, recv_is_self)
1132 var psig = prop.signature_for(type_recv)
1133 if not recv_is_self then psig = psig.not_for_self
1134 return psig
1135 end
1136
1137 # The invoked method (once computed)
1138 readable attr _prop: MMMethod
1139
1140 # The return type (if any) (once computed)
1141 readable attr _return_type: MMType
1142 end
1143
1144 # A possible call of constructor in a super class
1145 # Could be an explicit call or with the 'super' keyword
1146 class ASuperInitCall
1147 special AAbsSendExpr
1148 private meth register_super_init_call(v: TypingVisitor, property: MMMethod)
1149 do
1150 if parent != v.top_block and self != v.top_block then
1151 v.error(self, "Error: Constructor invocation {property} must not be in nested block.")
1152 end
1153 var cla = v.module[property.global.intro.local_class.global]
1154 var prev_class: MMLocalClass = null
1155 if not v.explicit_super_init_calls.is_empty then
1156 prev_class = v.explicit_super_init_calls.last.global.intro.local_class
1157 end
1158 var order = v.local_class.cshe.reverse_linear_extension
1159 if cla == v.local_class then
1160 v.explicit_other_init_call = true
1161 else if not order.has(cla) then
1162 v.error(self, "Error: Constructor of class {cla} must be one in {order.join(", ")}.")
1163 else if cla == prev_class then
1164 v.error(self, "Error: Only one super constructor invocation of class {cla} is allowed.")
1165 else
1166 var last_is_found = prev_class == null
1167 for c in order do
1168 if c == prev_class then
1169 last_is_found = true
1170 else if c == cla then
1171 if not last_is_found then
1172 v.error(self, "Error: Constructor of {c} must be invoked before constructor of {prev_class}")
1173 end
1174 v.explicit_super_init_calls.add(property)
1175 break
1176 end
1177 end
1178 end
1179 end
1180
1181 end
1182
1183 redef class ANewExpr
1184 special AAbsSendExpr
1185 redef meth after_typing(v)
1186 do
1187 var t = n_type.stype
1188 if t == null then return
1189 if t.local_class.global.is_abstract then
1190 v.error(self, "Error: try to instantiate abstract class {t.local_class}.")
1191 return
1192 end
1193 var name: Symbol
1194 if n_id == null then
1195 name = once "init".to_symbol
1196 else
1197 name = n_id.to_symbol
1198 end
1199
1200 do_typing(v, t, false, false, name, n_args.to_a, null)
1201 if prop == null then return
1202
1203 if not prop.global.is_init then
1204 v.error(self, "Error: {prop} is not a constructor.")
1205 return
1206 end
1207 _stype = t
1208 _is_typed = true
1209 end
1210 end
1211
1212
1213 redef class ASendExpr
1214 special ASuperInitCall
1215 # Name of the invoked property
1216 meth name: Symbol is abstract
1217
1218 # Raw arguments used (withour star transformation)
1219 meth raw_arguments: Array[PExpr] is abstract
1220
1221 # Closure definitions
1222 meth closure_defs: Array[PClosureDef] do return null
1223
1224 redef meth after_typing(v)
1225 do
1226 do_all_typing(v)
1227 end
1228
1229 private meth do_all_typing(v: TypingVisitor)
1230 do
1231 if not v.check_expr(n_expr) then return
1232 do_typing(v, n_expr.stype, n_expr.is_implicit_self, n_expr.is_self, name, raw_arguments, closure_defs)
1233 if prop == null then return
1234
1235 if prop.global.is_init then
1236 if not v.local_property.global.is_init then
1237 v.error(self, "Error: try to invoke constructor {prop} in a method.")
1238 else if not n_expr.is_self then
1239 v.error(self, "Error: constructor {prop} is not invoken on 'self'.")
1240 else
1241 register_super_init_call(v, prop)
1242 end
1243 end
1244
1245 _stype = return_type
1246 _is_typed = true
1247 end
1248 end
1249
1250 class ASendReassignExpr
1251 special ASendExpr
1252 special AReassignFormExpr
1253 readable attr _read_prop: MMMethod
1254 redef meth do_all_typing(v)
1255 do
1256 if not v.check_expr(n_expr) then return
1257 var raw_args = raw_arguments
1258 do_typing(v, n_expr.stype, n_expr.is_implicit_self, n_expr.is_self, name, raw_args, null)
1259 if prop == null then return
1260 if prop.global.is_init then
1261 if not v.local_property.global.is_init then
1262 v.error(self, "Error: try to invoke constructor {prop} in a method.")
1263 else if not n_expr.is_self then
1264 v.error(self, "Error: constructor {prop} is not invoken on 'self'.")
1265 end
1266 end
1267 var t = prop.signature_for(n_expr.stype).return_type
1268 if not n_expr.is_self then t = t.not_for_self
1269
1270 var t2 = do_rvalue_typing(v, t)
1271 if t2 == null then return
1272 v.check_conform(self, t2, n_value.stype)
1273
1274 _read_prop = prop
1275 var old_args = arguments
1276 raw_args.add(n_value)
1277
1278 do_typing(v, n_expr.stype, n_expr.is_implicit_self, n_expr.is_self, "{name}=".to_symbol, raw_args, null)
1279 if prop == null then return
1280 if prop.global.is_init then
1281 if not v.local_property.global.is_init then
1282 v.error(self, "Error: try to invoke constructor {prop} in a method.")
1283 else if not n_expr.is_self then
1284 v.error(self, "Error: constructor {prop} is not invoken on 'self'.")
1285 end
1286 end
1287
1288 _arguments = old_args # FIXME: What if star parameters do not match betwen the two methods?
1289 _is_typed = true
1290 end
1291 end
1292
1293 redef class ABinopExpr
1294 redef meth raw_arguments do return [n_expr2]
1295 end
1296 redef class AEqExpr
1297 redef meth name do return once "==".to_symbol
1298 end
1299 redef class ANeExpr
1300 redef meth name do return once "!=".to_symbol
1301 end
1302 redef class ALtExpr
1303 redef meth name do return once "<".to_symbol
1304 end
1305 redef class ALeExpr
1306 redef meth name do return once "<=".to_symbol
1307 end
1308 redef class AGtExpr
1309 redef meth name do return once ">".to_symbol
1310 end
1311 redef class AGeExpr
1312 redef meth name do return once ">=".to_symbol
1313 end
1314 redef class APlusExpr
1315 redef meth name do return once "+".to_symbol
1316 end
1317 redef class AMinusExpr
1318 redef meth name do return once "-".to_symbol
1319 end
1320 redef class AStarshipExpr
1321 redef meth name do return once "<=>".to_symbol
1322 end
1323 redef class AStarExpr
1324 redef meth name do return once "*".to_symbol
1325 end
1326 redef class ASlashExpr
1327 redef meth name do return once "/".to_symbol
1328 end
1329 redef class APercentExpr
1330 redef meth name do return once "%".to_symbol
1331 end
1332
1333 redef class AUminusExpr
1334 redef meth name do return once "unary -".to_symbol
1335 redef meth raw_arguments do return null
1336 end
1337
1338 redef class ACallFormExpr
1339 redef meth after_typing(v)
1340 do
1341 if n_expr != null and n_expr.is_implicit_self then
1342 var name = n_id.to_symbol
1343 var variable = v.variable_ctx[name]
1344 if variable != null then
1345 if variable isa ClosureVariable then
1346 var n = new AClosureCallExpr.init_aclosurecallexpr(n_id, n_args, n_closure_defs)
1347 replace_with(n)
1348 n.variable = variable
1349 n.after_typing(v)
1350 return
1351 else
1352 if not n_args.is_empty then
1353 v.error(self, "Error: {name} is variable, not a function.")
1354 return
1355 end
1356 var vform = variable_create(variable)
1357 vform.variable = variable
1358 replace_with(vform)
1359 vform.after_typing(v)
1360 return
1361 end
1362 end
1363 end
1364
1365 super
1366 end
1367
1368 redef meth closure_defs
1369 do
1370 if n_closure_defs == null or n_closure_defs.is_empty then
1371 return null
1372 else
1373 return n_closure_defs.to_a
1374 end
1375 end
1376
1377 # Create a variable acces corresponding to the call form
1378 meth variable_create(variable: Variable): AVarFormExpr is abstract
1379 end
1380
1381 redef class ACallExpr
1382 redef meth variable_create(variable)
1383 do
1384 return new AVarExpr.init_avarexpr(n_id)
1385 end
1386
1387 redef meth name do return n_id.to_symbol
1388 redef meth raw_arguments do return n_args.to_a
1389 end
1390
1391 redef class ACallAssignExpr
1392 redef meth variable_create(variable)
1393 do
1394 return new AVarAssignExpr.init_avarassignexpr(n_id, n_assign, n_value)
1395 end
1396
1397 redef meth name do return (n_id.text + "=").to_symbol
1398 redef meth raw_arguments do
1399 var res = n_args.to_a
1400 res.add(n_value)
1401 return res
1402 end
1403 end
1404
1405 redef class ACallReassignExpr
1406 special ASendReassignExpr
1407 redef meth variable_create(variable)
1408 do
1409 return new AVarReassignExpr.init_avarreassignexpr(n_id, n_assign_op, n_value)
1410 end
1411
1412 redef meth name do return n_id.to_symbol
1413 redef meth raw_arguments do return n_args.to_a
1414 end
1415
1416 redef class ABraExpr
1417 redef meth name do return once "[]".to_symbol
1418 redef meth raw_arguments do return n_args.to_a
1419 end
1420
1421 redef class ABraAssignExpr
1422 redef meth name do return once "[]=".to_symbol
1423 redef meth raw_arguments do
1424 var res = n_args.to_a
1425 res.add(n_value)
1426 return res
1427 end
1428 end
1429
1430 redef class ABraReassignExpr
1431 special ASendReassignExpr
1432 redef meth name do return once "[]".to_symbol
1433 redef meth raw_arguments do return n_args.to_a
1434 end
1435
1436 redef class AInitExpr
1437 redef meth name do return once "init".to_symbol
1438 redef meth raw_arguments do return n_args.to_a
1439 end
1440
1441 redef class AClosureCallExpr
1442 special AAbsAbsSendExpr
1443 redef meth after_typing(v)
1444 do
1445 var va = variable
1446 if va.closure.is_break then v.variable_ctx.unreash = true
1447 var sig = va.closure.signature
1448 var args = process_signature(v, sig, n_id.to_symbol, n_args.to_a)
1449 if not n_closure_defs.is_empty then
1450 process_closures(v, sig, n_id.to_symbol, n_closure_defs.to_a)
1451 end
1452 if args == null then return
1453 _prop_signature = sig
1454 _arguments = args
1455 _stype = sig.return_type
1456 _is_typed = true
1457 end
1458 end
1459
1460 redef class PClosureDef
1461 # The corresponding escapable object
1462 readable attr _escapable: EscapableBlock
1463
1464 attr _accept_typing2: Bool
1465 redef meth accept_typing(v)
1466 do
1467 # Typing is deferred, wait accept_typing2(v)
1468 if _accept_typing2 then super
1469 end
1470
1471 private meth accept_typing2(v: TypingVisitor, esc: EscapableClosure) is abstract
1472 end
1473
1474 redef class AClosureDef
1475 redef meth accept_typing2(v, esc)
1476 do
1477 _escapable = esc
1478
1479 var sig = esc.closure.signature
1480 if sig.arity != n_id.length then
1481 v.error(self, "Error: {sig.arity} automatic variable names expected, {n_id.length} found.")
1482 return
1483 end
1484
1485 closure = esc.closure
1486
1487 var old_var_ctx = v.variable_ctx
1488 var old_base_var_ctx = v.base_variable_ctx
1489 v.base_variable_ctx = v.variable_ctx
1490 v.variable_ctx = v.variable_ctx.sub(self)
1491 variables = new Array[AutoVariable]
1492 for i in [0..n_id.length[ do
1493 var va = new AutoVariable(n_id[i].to_symbol, self)
1494 variables.add(va)
1495 va.stype = sig[i]
1496 v.variable_ctx.add(va)
1497 end
1498
1499 _accept_typing2 = true
1500 accept_typing(v)
1501
1502 if v.variable_ctx.unreash == false then
1503 if closure.signature.return_type != null then
1504 v.error(self, "Control error: Reached end of block (a 'continue' with a value was expected).")
1505 else if closure.is_break then
1506 v.error(self, "Control error: Reached end of break block (a 'break' was expected).")
1507 end
1508 end
1509 v.variable_ctx = old_var_ctx
1510 v.base_variable_ctx = old_base_var_ctx
1511 end
1512 end
1513
1514 class ATypeCheckExpr
1515 special PExpr
1516 private meth check_expr_cast(v: TypingVisitor, n_expr: PExpr, n_type: PType)
1517 do
1518 if not v.check_expr(n_expr) then return
1519 var etype = n_expr.stype
1520 var ttype = n_type.stype
1521 if etype == ttype then
1522 v.warning(self, "Warning: Expression is already a {ttype}.")
1523 else if etype < ttype then
1524 v.warning(self, "Warning: Expression is already a {ttype} since it is a {etype}.")
1525 end
1526 end
1527 end
1528
1529 redef class AIsaExpr
1530 special ATypeCheckExpr
1531 redef meth after_typing(v)
1532 do
1533 check_expr_cast(v, n_expr, n_type)
1534 var variable = n_expr.its_variable
1535 if variable != null then
1536 _if_true_variable_ctx = v.variable_ctx.sub_with(self, variable, n_type.stype)
1537 end
1538 _stype = v.type_bool
1539 _is_typed = true
1540 end
1541 end
1542
1543 redef class AAsCastExpr
1544 special ATypeCheckExpr
1545 redef meth after_typing(v)
1546 do
1547 check_expr_cast(v, n_expr, n_type)
1548 _stype = n_type.stype
1549 _is_typed = _stype != null
1550 end
1551 end
1552
1553 redef class AProxyExpr
1554 redef meth after_typing(v)
1555 do
1556 if not n_expr.is_typed then return
1557 _is_typed = true
1558 if n_expr.is_statement then return
1559 _stype = n_expr.stype
1560 end
1561 end
1562
1563 redef class AOnceExpr
1564 redef meth accept_typing(v)
1565 do
1566 if v.once_count > 0 then
1567 v.warning(self, "Useless once in a once expression.")
1568 end
1569 v.once_count = v.once_count + 1
1570
1571 super
1572
1573 v.once_count = v.once_count - 1
1574 end
1575 end
1576