/* ----------------------------------------------------------------------------- Copyright 2020 Kevin P. Barry 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. ----------------------------------------------------------------------------- */ // Author: Kevin P. Barry [ta0kira@gmail.com] testcase "simple inference" { success Test$run() } define Test { run () { Int value <- get(10) } @type get<#x> (#x) -> (#x) get (x) { return x } } concrete Test { @type run () -> () } testcase "inference mismatch" { error require "String" require "Int" } define Test { run () { String value <- get(10) } @type get<#x> (#x) -> (#x) get (x) { return x } } concrete Test { @type run () -> () } testcase "nested inference" { success Test$run() } concrete Type<#x> { @type create () -> (Type<#x>) } define Type { create () { return Type<#x>{ } } } define Test { run () { Type value <- get(Type$create()) } @type get<#x> (Type<#x>) -> (Type<#x>) get (x) { return x } } concrete Test { @type run () -> () } testcase "simple inference with qualification" { success Test$run() } define Test { run () { Int value <- Test$get(10) } @type get<#x> (#x) -> (#x) get (x) { return x } } concrete Test { @type run () -> () } testcase "inference mismatch with qualification" { error require "String" require "Int" } define Test { run () { String value <- Test$get(10) } @type get<#x> (#x) -> (#x) get (x) { return x } } concrete Test { @type run () -> () } testcase "nested inference with qualification" { success Test$run() } concrete Type<#x> { @type create () -> (Type<#x>) } define Type { create () { return Type<#x>{ } } } define Test { run () { Type value <- Test$get(Type$create()) } @type get<#x> (Type<#x>) -> (Type<#x>) get (x) { return x } } concrete Test { @type run () -> () } testcase "inference conflict" { error require "String" require "Int" } concrete Type<#x> { @type create () -> (Type<#x>) } define Type { create () { return Type<#x>{ } } } define Test { run () { Type value <- get(Type$create(),"bad") } @type get<#x> (Type<#x>,#x) -> (Type<#x>) get (x,_) { return x } } concrete Test { @type run () -> () } testcase "inference from filter" { error require "#x.+get.+Formatted" require "String" require "value2" exclude "value1" } define Test { run () { Formatted value1 <- get("value") String value2 <- get("value") } @type get<#x> #x allows Formatted (#x) -> (#x) get (x) { return x } } concrete Test { @type run () -> () } testcase "inference from filter without param" { error require "#x.+get.+Formatted" require "String" require "value2" exclude "value1" } define Test { run () { Formatted value1 <- get("value") String value2 <- get("value") } @type get<#y,#x> #x allows #y (#x) -> (#x) get (x) { return x } } concrete Test { @type run () -> () } testcase "inference from filter including param" { error require "#x.+get.+Type" } concrete Type<#x> { @type create () -> (Type<#x>) } define Type { create () { return Type<#x>{ } } } define Test { run () { Type value2 <- get(Type$create()) } @type get<#x> #x allows Type<#x> (#x) -> (#x) get (x) { return x } } concrete Test { @type run () -> () } testcase "clashing param filter in the same scope" { success Test$run() } define Test { run () { \ get1() } @type get1<#x> #x requires Int () -> () get1 () { String value <- get2("message") } @type get2<#x> (#x) -> (#x) get2 (x) { return x } } concrete Test { @type run () -> () }