packages feed

zeolite-lang-0.7.0.0: tests/inference.0rt

/* -----------------------------------------------------------------------------
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<Int> value <- get<?>(Type<Int>$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<Int> value <- Test$get<?>(Type<Int>$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<Int> value <- get<?>(Type<Int>$create(),"bad")
  }

  @type get<#x> (Type<#x>,#x) -> (Type<#x>)
  get (x,_) {
    return x
  }
}

concrete Test {
  @type run () -> ()
}


testcase "inference from filter" {
  error
  require "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 () -> ()
}