From f7e8ab62ae7fe8524a848ec404c10363ab9ec7a2 Mon Sep 17 00:00:00 2001 From: Vadim Belman Date: Mon, 5 Apr 2021 17:02:08 -0400 Subject: [PATCH] Add a test for possible overriding of delegated methods In support of rakudo/rakudo#4303 --- S12-attributes/delegation.t | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/S12-attributes/delegation.t b/S12-attributes/delegation.t index 92cd136889..8e880f20e9 100644 --- a/S12-attributes/delegation.t +++ b/S12-attributes/delegation.t @@ -2,7 +2,7 @@ use v6; use Test; -plan 65; +plan 68; =begin desc @@ -108,7 +108,7 @@ class PairTest { { class ReFrontend { has $.backend is rw handles /^hi|oo/ }; ok ReFrontend.new, "class definition using a smartmatch handle worked"; - + { my $a; ok ($a = ReFrontend.new), "basic instantiation worked (3)"; @@ -202,4 +202,26 @@ class PairTest { dies-ok { $a.d() }, '... but non existing methods still die'; } +# A class must be able to override a delegated method. +eval-lives-ok q:to/CODE/, "class overrides a delegated method"; +role R { + has $.backend handles ; +} +class C does R { + method Str { "class C" } +} +CODE + +{ # As long as the previous test succeeds, make sure we do override the delegated method. + my role ROverridable { + has $.backend handles ; + } + my class Overrider does ROverridable { + method hi { "class C" } + } + my $a = Overrider.new(backend => Backend1.new); + is $a.hi, 'class C', "backend method overriden"; + is $a.cool, 1337, "un-overriden backend method is intact"; +} + # vim: expandtab shiftwidth=4