From 9a229c78162bbaab71d7f59c574d8faa8889bca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Fri, 20 Dec 2024 12:40:20 +0100 Subject: [PATCH] De-duplicate error messages --- src/compiler/crystal/macros/methods.cr | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler/crystal/macros/methods.cr b/src/compiler/crystal/macros/methods.cr index 06cf6165eab8..2ee24a6b9892 100644 --- a/src/compiler/crystal/macros/methods.cr +++ b/src/compiler/crystal/macros/methods.cr @@ -2080,10 +2080,11 @@ module Crystal def self.instance_vars(type, name_loc) if type.is_a?(InstanceVarContainer) unless type.program.top_level_semantic_complete? + message = "`TypeNode#instance_vars` cannot be called in the top-level scope: instance vars are not yet initialized" if name_loc - raise Crystal::TypeException.new("`TypeNode#instance_vars` cannot be called in the top-level scope: instance vars are not yet initialized", name_loc) + raise Crystal::TypeException.new(message, name_loc) else - raise Crystal::TypeException.new("`TypeNode#instance_vars` cannot be called in the top-level scope: instance vars are not yet initialized") + raise Crystal::TypeException.new(message) end end ArrayLiteral.map(type.all_instance_vars) do |name, ivar| @@ -2099,10 +2100,11 @@ module Crystal def self.has_inner_pointers?(type, name_loc) unless type.program.top_level_semantic_complete? + message = "`TypeNode#has_inner_pointers?` cannot be called in the top-level scope: instance vars are not yet initialized" if name_loc - raise Crystal::TypeException.new("`TypeNode#has_inner_pointers?` cannot be called in the top-level scope: instance vars are not yet initialized", name_loc) + raise Crystal::TypeException.new(message, name_loc) else - raise Crystal::TypeException.new("`TypeNode#has_inner_pointers?` cannot be called in the top-level scope: instance vars are not yet initialized") + raise Crystal::TypeException.new(message) end end