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..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}" + 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