tests: add base_covar_adapt.nit base_gen_nest.nit to test dead-code adaptations
authorJean Privat <jean@pryen.org>
Fri, 25 Mar 2016 02:46:35 +0000 (22:46 -0400)
committerJean Privat <jean@pryen.org>
Fri, 25 Mar 2016 05:25:19 +0000 (01:25 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

tests/base_covar_adapt.nit [new file with mode: 0644]
tests/base_gen_nest.nit [new file with mode: 0644]
tests/sav/base_covar_adapt.res [new file with mode: 0644]
tests/sav/base_covar_adapt_alt1.res [new file with mode: 0644]
tests/sav/base_covar_adapt_alt2.res [new file with mode: 0644]
tests/sav/base_gen_nest.res [new file with mode: 0644]
tests/sav/nitce/base_covar_adapt_alt1.res [new file with mode: 0644]
tests/sav/nitce/base_covar_adapt_alt2.res [new file with mode: 0644]
tests/sav/nitcg/fixme/base_covar_adapt_alt2.res [new file with mode: 0644]

diff --git a/tests/base_covar_adapt.nit b/tests/base_covar_adapt.nit
new file mode 100644 (file)
index 0000000..54f60bd
--- /dev/null
@@ -0,0 +1,35 @@
+# This file is part of NIT ( http://www.nitlanguage.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.
+
+import core::kernel
+
+class A[E]
+       fun foo(e: E): E
+       do
+               if e == null then e = true
+               return e
+       end
+end
+
+fun foo(a: A[nullable Object], o: nullable Object) do
+       a.foo(o).as(not null).output
+end
+
+foo(new A[nullable Object], 1.0)
+foo(new A[nullable Float], 1.0)
+foo(new A[Float], 1.0)
+
+foo(new A[nullable Object], null)
+#alt1#foo(new A[nullable Float], null)
+#alt2#foo(new A[Float], null)
diff --git a/tests/base_gen_nest.nit b/tests/base_gen_nest.nit
new file mode 100644 (file)
index 0000000..13f8105
--- /dev/null
@@ -0,0 +1,31 @@
+# This file is part of NIT ( http://www.nitlanguage.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.
+
+import core::kernel
+
+class G[E: Object]
+       var e: E
+       fun foo: Object
+       do
+               var e = self.e
+               if e isa G[Object] then
+                       return e.foo
+               end
+               return e
+       end
+end
+
+var g1 = new G[Float](1.0)
+var g2 = new G[G[Float]](g1)
+g2.foo.output
diff --git a/tests/sav/base_covar_adapt.res b/tests/sav/base_covar_adapt.res
new file mode 100644 (file)
index 0000000..5e640b5
--- /dev/null
@@ -0,0 +1,4 @@
+1.000000
+1.000000
+1.000000
+true
diff --git a/tests/sav/base_covar_adapt_alt1.res b/tests/sav/base_covar_adapt_alt1.res
new file mode 100644 (file)
index 0000000..0b0273c
--- /dev/null
@@ -0,0 +1,5 @@
+Runtime error: Cast failed. Expected `E`, got `Bool` (alt/base_covar_adapt_alt1.nit:20)
+1.000000
+1.000000
+1.000000
+true
diff --git a/tests/sav/base_covar_adapt_alt2.res b/tests/sav/base_covar_adapt_alt2.res
new file mode 100644 (file)
index 0000000..bc3ebbd
--- /dev/null
@@ -0,0 +1,5 @@
+Runtime error: Cast failed. Expected `E`, got `null` (alt/base_covar_adapt_alt2.nit:18)
+1.000000
+1.000000
+1.000000
+true
diff --git a/tests/sav/base_gen_nest.res b/tests/sav/base_gen_nest.res
new file mode 100644 (file)
index 0000000..961b372
--- /dev/null
@@ -0,0 +1 @@
+1.000000
diff --git a/tests/sav/nitce/base_covar_adapt_alt1.res b/tests/sav/nitce/base_covar_adapt_alt1.res
new file mode 100644 (file)
index 0000000..326b920
--- /dev/null
@@ -0,0 +1,5 @@
+1.000000
+1.000000
+1.000000
+true
+true
diff --git a/tests/sav/nitce/base_covar_adapt_alt2.res b/tests/sav/nitce/base_covar_adapt_alt2.res
new file mode 100644 (file)
index 0000000..326b920
--- /dev/null
@@ -0,0 +1,5 @@
+1.000000
+1.000000
+1.000000
+true
+true
diff --git a/tests/sav/nitcg/fixme/base_covar_adapt_alt2.res b/tests/sav/nitcg/fixme/base_covar_adapt_alt2.res
new file mode 100644 (file)
index 0000000..4ad3dc3
--- /dev/null
@@ -0,0 +1 @@
+UNDEFINED