From 5f9d6a9e71b603b61c191bb66b506cf7ff22c212 Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Wed, 7 Jul 2021 23:20:38 +0800 Subject: [PATCH] Add extra specs for #10507 --- spec/compiler/semantic/abstract_def_spec.cr | 60 ++++++++++++++++++++- spec/compiler/semantic/proc_spec.cr | 24 ++++++++- 2 files changed, 81 insertions(+), 3 deletions(-) diff --git a/spec/compiler/semantic/abstract_def_spec.cr b/spec/compiler/semantic/abstract_def_spec.cr index c95a6e5aa664..9f187ab9e64c 100644 --- a/spec/compiler/semantic/abstract_def_spec.cr +++ b/spec/compiler/semantic/abstract_def_spec.cr @@ -344,7 +344,7 @@ describe "Semantic: abstract def" do end it "doesn't error if implements with parent class" do - semantic %( + assert_no_errors %( class Parent; end class Child < Parent; end @@ -359,8 +359,64 @@ describe "Semantic: abstract def" do ) end + it "doesn't error if implements with generic parent class instance" do + assert_no_errors %( + class Parent(T); end + class Child(T) < Parent(T); end + + abstract class Foo + abstract def foo(x : Child(Int32)) + end + + class Bar < Foo + def foo(x : Parent(Int32)) + end + end + ) + end + + it "doesn't error if implements with included module" do + assert_no_errors %( + module Moo + end + + module Moo2 + include Moo + end + + abstract class Foo + abstract def foo(x : Moo2) + end + + class Bar < Foo + def foo(x : Moo) + end + end + ) + end + + it "doesn't error if implements with generic included module instance" do + assert_no_errors %( + module Moo(T) + end + + module Moo2(T) + include Moo(T) + end + + abstract class Foo + abstract def foo(x : Moo2(Int32)) + end + + class Bar < Foo + def foo(x : Moo(Int32)) + end + end + ) + end + it "doesn't error if implements with parent module" do - semantic %( + assert_no_errors %( module Moo end diff --git a/spec/compiler/semantic/proc_spec.cr b/spec/compiler/semantic/proc_spec.cr index a77ca8f654bc..798e70c269cc 100644 --- a/spec/compiler/semantic/proc_spec.cr +++ b/spec/compiler/semantic/proc_spec.cr @@ -656,7 +656,7 @@ describe "Semantic: proc" do "no overload matches" end - it "allows invoking a function with a generic subtype" do + it "allows invoking a function with a generic subtype (1)" do assert_type(%( module Moo def foo @@ -678,6 +678,28 @@ describe "Semantic: proc" do )) { int32 } end + it "allows invoking a function with a generic subtype (2)" do + assert_type(%( + module Moo(T) + def foo + 1 + end + end + + class Foo(T) + include Moo(T) + end + + def func(&block : Moo(Int32) -> _) + block + end + + foo = Foo(Int32).new + f = func { |moo| moo.foo } + f.call foo + )) { int32 } + end + it "gets pointer to lib fun without specifying types" do assert_type(%( lib LibFoo