File tree 2 files changed +20
-6
lines changed
src/compiler/crystal/semantic
2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -357,4 +357,13 @@ describe "Semantic: super" do
357
357
) ,
358
358
" undefined method 'Base#method()'"
359
359
end
360
+
361
+ it " errors on super outside method (#4481)" do
362
+ assert_error %(
363
+ class Foo
364
+ super
365
+ end
366
+ ) ,
367
+ " can't use 'super' outside method"
368
+ end
360
369
end
Original file line number Diff line number Diff line change @@ -551,7 +551,7 @@ class Crystal::Call
551
551
raise " there's no superclass in this scope"
552
552
end
553
553
554
- enclosing_def = enclosing_def()
554
+ enclosing_def = enclosing_def(" super " )
555
555
556
556
# TODO: do this better
557
557
lookup = enclosing_def.owner
@@ -594,7 +594,7 @@ class Crystal::Call
594
594
end
595
595
596
596
def lookup_previous_def_matches (arg_types, named_args_types)
597
- enclosing_def = enclosing_def()
597
+ enclosing_def = enclosing_def(" previous_def " )
598
598
599
599
previous_item = enclosing_def.previous
600
600
unless previous_item
@@ -623,13 +623,18 @@ class Crystal::Call
623
623
typed_defs
624
624
end
625
625
626
- def enclosing_def
626
+ def enclosing_def ( context )
627
627
fun_literal_context = parent_visitor.fun_literal_context
628
628
if fun_literal_context.is_a?(Def )
629
- fun_literal_context
630
- else
631
- parent_visitor.untyped_def
629
+ return fun_literal_context
630
+ end
631
+
632
+ untyped_def = parent_visitor.untyped_def?
633
+ if untyped_def
634
+ return untyped_def
632
635
end
636
+
637
+ raise " can't use '#{ context } ' outside method"
633
638
end
634
639
635
640
def on_new_subclass
You can’t perform that action at this time.
0 commit comments