redef class PType
fun stype: MMType do return _stype.as(not null)
+ fun is_typed: Bool do return _stype != null
var _stype: nullable MMType
redef fun after_typing(v)
if n_expr != null then v.variable_ctx.mark_is_set(va)
if n_type != null then
+ if not n_type.is_typed then return
va.stype = n_type.stype
if n_expr != null then
v.check_conform_expr(n_expr.as(not null), va.stype)
special AAbsSendExpr
redef fun after_typing(v)
do
- if n_type._stype == null then return
+ if not n_type.is_typed then return
var t = n_type.stype
if t.local_class.global.is_abstract then
v.error(self, "Error: try to instantiate abstract class {t.local_class}.")
private fun check_expr_cast(v: TypingVisitor, n_expr: PExpr, n_type: PType)
do
if not v.check_expr(n_expr) then return
+ if not n_type.is_typed then return
var etype = n_expr.stype
var ttype = n_type.stype
if etype == ttype then
redef fun after_typing(v)
do
check_expr_cast(v, n_expr, n_type)
+ if not n_type.is_typed then return
var variable = n_expr.its_variable
if variable != null then
_if_true_variable_ctx = v.variable_ctx.sub_with(self, variable, n_type.stype)
redef fun after_typing(v)
do
check_expr_cast(v, n_expr, n_type)
+ if not n_type.is_typed then return
_stype = n_type.stype
_is_typed = _stype != null
end
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2009 Jean Privat <jean@pryen.org>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#alt1#class Fail[E]
+#alt1#end
+
+fun trash(g: Char) do end
+
+var ok: Int = 1
+var a: Fail = 5
+trash(a)
+var na: nullable Fail = null
+trash(na)
+
+trash(ok isa Fail)
+trash(new Fail)
+trash(new Fail.fail(5))
+trash(ok.as(Fail))
+
--- /dev/null
+alt/error_expr_not_ok_alt2.nit:19,19--22: Error: Method or variable 'fail' unknown in A.
+alt/error_expr_not_ok_alt2.nit:21,11--14: Error: Method or variable 'fail' unknown in A.
+alt/error_expr_not_ok_alt2.nit:22,26--29: Error: Method or variable 'fail' unknown in A.
+alt/error_expr_not_ok_alt2.nit:24,8--11: Error: Method or variable 'fail' unknown in A.
+alt/error_expr_not_ok_alt2.nit:25,9--12: Error: Method or variable 'fail' unknown in A.
+alt/error_expr_not_ok_alt2.nit:33,11: Type error: class Fail not found in module error_expr_not_ok_alt2.
+alt/error_expr_not_ok_alt2.nit:33,22: Type error: class Fail not found in module error_expr_not_ok_alt2.
+alt/error_expr_not_ok_alt2.nit:40,1--7: Error: Method 'fail' doesn't exists in Int.
+alt/error_expr_not_ok_alt2.nit:42,7--9: Type error: expected A, got Int
+alt/error_expr_not_ok_alt2.nit:43,1--8: Error: Method 'fail' doesn't exists in Int.
+alt/error_expr_not_ok_alt2.nit:60,20--20: Type error: expected A, got Int
+alt/error_expr_not_ok_alt2.nit:62,7--27: Type error: expected A, got Int
+alt/error_expr_not_ok_alt2.nit:66,21--21: Type error: expected A, got Int
+alt/error_expr_not_ok_alt2.nit:73,7--18: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:74,7--18: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:75,7--18: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:76,7--19: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:77,7--19: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:78,7--19: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:79,7--14: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:81,7--15: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:84,7--15: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:86,7--15: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:87,7--15: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:88,7--18: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:90,7--14: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:93,7--14: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:96,7--15: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:99,7--15: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt2.nit:102,7--16: Type error: expected A, got Int
+alt/error_expr_not_ok_alt2.nit:105,7--14: Type error: expected A, got Int
+alt/error_expr_not_ok_alt2.nit:108,7--14: Type error: expected A, got Int
+alt/error_expr_not_ok_alt2.nit:111,7--14: Type error: expected A, got Int
+alt/error_expr_not_ok_alt2.nit:114,7--14: Type error: expected A, got Int
+alt/error_expr_not_ok_alt2.nit:117,7--14: Type error: expected A, got Int
+alt/error_expr_not_ok_alt2.nit:122,7--15: Error: Attribute _fail doesn't exists in String.
+alt/error_expr_not_ok_alt2.nit:123,1--13: Error: Attribute _fail doesn't exists in String.
+alt/error_expr_not_ok_alt2.nit:124,1--14: Error: Attribute _fail doesn't exists in String.
+alt/error_expr_not_ok_alt2.nit:131,7--14: Type error: expected A, got Int
+alt/error_expr_not_ok_alt2.nit:149,7--24: Type error: expected A, got String
+alt/error_expr_not_ok_alt2.nit:150,7--17: Type error: expected A, got Int
+alt/error_expr_not_ok_alt2.nit:152,7--18: Type error: expected A, got Bool