Skip to content

Commit

Permalink
Showing 3 changed files with 23 additions and 3 deletions.
7 changes: 7 additions & 0 deletions spec/compiler/type_inference/visibility_modifiers_spec.cr
Original file line number Diff line number Diff line change
@@ -377,4 +377,11 @@ describe "Visibility modifiers" do
Foo::Bar(Int32).new.bar
)) { int32 }
end

it "gives correct error on unknown call (#2838)" do
assert_error %(
private foo
),
"undefined local variable or method 'foo'"
end
end
13 changes: 13 additions & 0 deletions src/compiler/crystal/semantic/main_visitor.cr
Original file line number Diff line number Diff line change
@@ -2640,6 +2640,19 @@ module Crystal
false
end

def visit(node : VisibilityModifier)
exp = node.exp
exp.accept self

# Only check for calls that didn't resolve to a macro:
# all other cases are already covered in TopLevelVisitor
if exp.is_a?(Call) && !exp.expanded
node.raise "can't apply visibility modifier"
end

false
end

# # Helpers

def check_closured(var)
6 changes: 3 additions & 3 deletions src/compiler/crystal/semantic/top_level_visitor.cr
Original file line number Diff line number Diff line change
@@ -694,9 +694,9 @@ module Crystal

return false
when Call
if exp.expanded
return false
end
# Don't give an error yet: wait to see if the
# call doesn't resolve to a method/macro
return false
end

node.raise "can't apply visibility modifier"

0 comments on commit ca6154d

Please sign in to comment.