mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 18:34:03 +03:00
Ascribed Type checks for a -> b function types (#7298)
This commit is contained in:
parent
6864792653
commit
e59513065d
@ -660,6 +660,8 @@ class IrToTruffle(
|
||||
def extractAscribedType(t: IR.Expression): List[Type] = t match {
|
||||
case u: IR.Type.Set.Union => u.operands.flatMap(extractAscribedType)
|
||||
case p: IR.Application.Prefix => extractAscribedType(p.function)
|
||||
case _: IR.Type.Function =>
|
||||
List(context.getTopScope().getBuiltins().function())
|
||||
case t => {
|
||||
t.getMetadata(TypeNames) match {
|
||||
case Some(
|
||||
|
@ -64,6 +64,7 @@ import project.Network.Http.Request_Spec as Http_Request_Spec
|
||||
import project.Network.Http_Spec
|
||||
import project.Network.URI_Spec
|
||||
|
||||
import project.Runtime.Ascribed_Parameters_Spec
|
||||
import project.Runtime.Lazy_Spec
|
||||
import project.Runtime.Lazy_Generator_Spec
|
||||
import project.Runtime.Managed_Resource_Spec
|
||||
@ -129,6 +130,7 @@ main = Test_Suite.run_main <|
|
||||
Range_Spec.spec
|
||||
Ref_Spec.spec
|
||||
Regex_Spec.spec
|
||||
Ascribed_Parameters_Spec.spec
|
||||
Lazy_Spec.spec
|
||||
Runtime_Spec.spec
|
||||
Self_Type_Spec.spec
|
||||
|
64
test/Tests/src/Runtime/Ascribed_Parameters_Spec.enso
Normal file
64
test/Tests/src/Runtime/Ascribed_Parameters_Spec.enso
Normal file
@ -0,0 +1,64 @@
|
||||
from Standard.Base import all
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
|
||||
import Standard.Base.Errors.Common.Type_Error
|
||||
|
||||
spec = Test.group "Function Ascribed Parameters" <|
|
||||
t1 (f1 : Function) =
|
||||
f1 "x"
|
||||
|
||||
t2 (f2 : (Text -> Any)) =
|
||||
f2 "x"
|
||||
|
||||
t3 (f3 : (Integer | Function)) = case f3 of
|
||||
n : Integer -> n*7
|
||||
_ -> f3 "x"
|
||||
|
||||
t4 (f4 : (Integer | (Text -> Any))) = case f4 of
|
||||
n : Integer -> n*7
|
||||
_ -> f4 "x"
|
||||
|
||||
surround x = "|" + x + "|"
|
||||
|
||||
with_type_error ~action = Panic.catch Type_Error action panic->panic.convert_to_dataflow_error
|
||||
|
||||
Test.specify "t1 with surround type check" <|
|
||||
(t1 surround) . should_equal "|x|"
|
||||
|
||||
Test.specify "t2 with surround type check" <|
|
||||
(t2 surround) . should_equal "|x|"
|
||||
|
||||
Test.specify "t3 with surround type check" <|
|
||||
(t3 surround) . should_equal "|x|"
|
||||
|
||||
Test.specify "t4 with surround type check" <|
|
||||
(t4 surround) . should_equal "|x|"
|
||||
|
||||
Test.specify "t1 with 42 type check" <|
|
||||
with_type_error (t1 6) . should_fail_with Type_Error
|
||||
|
||||
Test.specify "t2 with 42 type check" <|
|
||||
with_type_error (t2 6) . should_fail_with Type_Error
|
||||
|
||||
Test.specify "t3 with 42 type check" <|
|
||||
(t3 6) . should_equal 42
|
||||
|
||||
Test.specify "t4 with 42 type check" <|
|
||||
(t4 6) . should_equal 42
|
||||
|
||||
Test.specify "t1 with text type check" <|
|
||||
with_type_error (t1 "hi") . should_fail_with Type_Error
|
||||
|
||||
Test.specify "t2 with text type check" <|
|
||||
with_type_error (t2 "hi") . should_fail_with Type_Error
|
||||
|
||||
Test.specify "t3 with text type check" <|
|
||||
with_type_error (t3 "hi") . should_fail_with Type_Error
|
||||
|
||||
Test.specify "t4 with text type check" <|
|
||||
with_type_error (t4 "hi") . should_fail_with Type_Error
|
||||
|
||||
|
||||
main = Test_Suite.run_main spec
|
Loading…
Reference in New Issue
Block a user