From 0363c43dfff45cbe60a0dfe83218cae742459b0e Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 31 Jan 2021 00:38:17 -0700 Subject: [PATCH] Fix described_class Must be a macro, otherwise the return type becomes a union of all nested described_class methods, which can cause weird errors. --- src/spectator/dsl/groups.cr | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/spectator/dsl/groups.cr b/src/spectator/dsl/groups.cr index 3dc353b..001f4fb 100644 --- a/src/spectator/dsl/groups.cr +++ b/src/spectator/dsl/groups.cr @@ -86,17 +86,17 @@ module Spectator::DSL what.is_a?(TypeNode) || what.is_a?(Union)) && (described_type = what.resolve?).is_a?(TypeNode) %} - private def described_class - {{described_type}} + private macro described_class + {{what}} end - {% if described_type < Reference || described_type < Value %} - subject { described_class.new } - {% else %} - private def subject + subject do + {% if described_type.class? || described_type.struct? %} + described_class.new + {% else %} described_class - end - {% end %} + {% end %} + end {% else %} private def _spectator_implicit_subject {{what}}