From 08f5362f2d6a6cbf2caee6bd39d5b8ffd4f1df1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Mon, 2 Jun 2025 15:38:15 +0200 Subject: [PATCH 1/2] Improve error message fo `pointerof` --- spec/compiler/semantic/pointer_spec.cr | 8 ++++++-- src/compiler/crystal/semantic/main_visitor.cr | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/spec/compiler/semantic/pointer_spec.cr b/spec/compiler/semantic/pointer_spec.cr index 26a6683a8ac5..43c0a019dd8b 100644 --- a/spec/compiler/semantic/pointer_spec.cr +++ b/spec/compiler/semantic/pointer_spec.cr @@ -63,11 +63,15 @@ describe "Semantic: pointer" do end it "pointer of class raises error" do - assert_error "pointerof(Int32)", "can't take address of Int32" + assert_error "pointerof(Int32)", "can't take address of Int32 because it's a Path. `pointerof` expects a variable or constant." + end + + it "pointer of class raises error" do + assert_error "def foo; foo; end; pointerof(foo)", "can't take address of foo because it's a Call. `pointerof` expects a variable or constant." end it "pointer of value error" do - assert_error "pointerof(1)", "can't take address of 1" + assert_error "pointerof(1)", "can't take address of 1 because it's a NumberLiteral. `pointerof` expects a variable or constant." end it "types pointer value on typedef" do diff --git a/src/compiler/crystal/semantic/main_visitor.cr b/src/compiler/crystal/semantic/main_visitor.cr index b58ec06a8522..b12e5be0af4d 100644 --- a/src/compiler/crystal/semantic/main_visitor.cr +++ b/src/compiler/crystal/semantic/main_visitor.cr @@ -2589,7 +2589,7 @@ module Crystal # "undefined local variable or method" node.exp.accept self - node.exp.raise "can't take address of #{node.exp}" + node.exp.raise "can't take address of #{node.exp} because it's a #{ node.exp.class_desc }. `pointerof` expects a variable or constant." end node.bind_to var From 1bab2f3dc471500bfb84c0abd42bc51cb4a75cfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Fri, 6 Jun 2025 11:34:46 +0200 Subject: [PATCH 2/2] format --- src/compiler/crystal/semantic/main_visitor.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/crystal/semantic/main_visitor.cr b/src/compiler/crystal/semantic/main_visitor.cr index b12e5be0af4d..bccbe5d601e1 100644 --- a/src/compiler/crystal/semantic/main_visitor.cr +++ b/src/compiler/crystal/semantic/main_visitor.cr @@ -2589,7 +2589,7 @@ module Crystal # "undefined local variable or method" node.exp.accept self - node.exp.raise "can't take address of #{node.exp} because it's a #{ node.exp.class_desc }. `pointerof` expects a variable or constant." + node.exp.raise "can't take address of #{node.exp} because it's a #{node.exp.class_desc}. `pointerof` expects a variable or constant." end node.bind_to var