Skip to content

Commit

Permalink
Added tests for callref with sav
Browse files Browse the repository at this point in the history
New tests in `tests/test_callref.nit`

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>
  • Loading branch information
lvboudre committed Oct 1, 2019
1 parent 57b1d75 commit 556a50d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/rapid_type_analysis.nit
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,6 @@ redef class ACallrefExpr
redef fun accept_rapid_type_visitor(v)
do
super
v.analysis.live_types.has(callsite.recv)
v.add_type(callsite.recv.as(MClassType))
v.add_type(mtype.as(MClassType))
end
Expand Down
13 changes: 13 additions & 0 deletions tests/sav/test_callref.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
in A::fun1
in B::fun1
100
in B::fun1
in B::fun1
in B::fun1
110
3
5
x is null
x is null
x is test
x is 100
30 changes: 15 additions & 15 deletions src/test_callref.nit → tests/test_callref.nit
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This file is part of NIT ( http://www.nitlanguage.org ).
#
# Copyright 2019-2020 Louis-Vincent Boudreault <lv.boudreault95@gmail.com>
#
# 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
Expand Down Expand Up @@ -63,42 +61,44 @@ end

var a = new A
var b: A = new B

var f1 = &a.fun1
assert f1.call == "in A::fun1"
print f1.call # "in A::fun1"

var f2 = &b.fun1
assert f2.call == "in B::fun1"
print f2.call # "in B::fun1"

var f3 = &10.mult_by
assert f3.call(10) == 100
print f3.call(10) # 100

var f4 = &f2.call
assert f4.call == "in B::fun1"
print f4.call # "in B::fun1"

var f5: Fun0[Object] = &f4.call
assert f5.call == "in B::fun1"
assert f5.call == "in B::fun1"
print f5.call
print f5.call

assert (&10.toto).call(100) == 110
assert (&"allo".toto).call(1) == 2
print((&10.toto).call(100)) # 110
print((&"allo".toto).call(2)) # 3

var cnt = new Counter
var p1 = &cnt.incr
var ps = [p1,p1,p1,p1,p1]

for p in ps do p.call
assert cnt.x == 5
print cnt.x # 5

var c1 = new C[nullable Object](null)
var c2 = new C[nullable Int](null)

var f6 = &c1.to_s
var f7 = &c2.to_s

assert f6.call == "x is null"
assert f7.call == "x is null"
print f6.call # "x is null"
print f7.call # "x is null"

c1.x = "test"
c2.x = 100

assert f6.call == "x is test"
assert f7.call == "x is 100"
print f6.call # "x is test"
print f7.call # "x is 100"

0 comments on commit 556a50d

Please sign in to comment.