Skip to content

Commit 57ff630

Browse files
committed
[GR-18163] Detect invalid returns in module bodies.
PullRequest: truffleruby/2210
2 parents d0197c5 + 447e53f commit 57ff630

File tree

13 files changed

+59
-41
lines changed

13 files changed

+59
-41
lines changed

spec/tags/language/block_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
fails:A block yielded a single Array when non-symbol keys are in a keyword arguments Hash raises an ArgumentError
21
fails:A block yielded a single Array calls #to_hash on the argument but ignores result when optional argument and keyword argument accepted
32
fails:Post-args with optional args with a circular argument reference raises a SyntaxError if using an existing local with the same name as the argument
43
fails:Post-args with optional args with a circular argument reference raises a SyntaxError if there is an existing method with the same name as the argument

spec/tags/language/constants_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
fails:top-level constant lookup on a class searches Object successfully after searching other scopes
21
fails:Module#private_constant marked constants NameError by #private_constant has the defined class as the :name attribute
32
fails:top-level constant lookup on a class does not search Object after searching other scopes
43
fails:Module#private_constant marked constants sends #const_missing to the original class or module

spec/tags/language/delegation_tags.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

spec/tags/language/for_tags.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

spec/tags/language/method_tags.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
fails:A method assigns local variables from method parameters for definition 'def m() end'
22
fails:A method assigns local variables from method parameters for definition 'def m(*a) a end'
3-
fails:A method assigns local variables from method parameters for definition 'def m(a=1, b:) [a, b] end'
4-
fails:A method assigns local variables from method parameters for definition 'def m(a=1, b: 2) [a, b] end'
53
fails:A method assigns local variables from method parameters for definition 'def m(a=1, **) a end'
6-
fails:A method assigns local variables from method parameters for definition 'def m(*, a:) a end'
7-
fails:A method assigns local variables from method parameters for definition 'def m(*a, b:) [a, b] end'
8-
fails:A method assigns local variables from method parameters for definition 'def m(*, a: 1) a end'
9-
fails:A method assigns local variables from method parameters for definition 'def m(*a, b: 1) [a, b] end'
104
fails:A method assigns local variables from method parameters for definition 'def m(*a, **) a end'
115
fails:A method assigns local variables from method parameters for definition 'def m(*, **k) k end'
126
fails:A method assigns local variables from method parameters for definition 'def m(a = nil, **k) [a, k] end'

spec/tags/language/pattern_matching_tags.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
fails:Pattern matching can be standalone in operator that deconstructs value
21
fails:Pattern matching extends case expression with case/in construction
32
fails:Pattern matching allows using then operator
4-
fails:Pattern matching warns about pattern matching is experimental feature
53
fails:Pattern matching binds variables
64
fails:Pattern matching cannot mix in and when operators
75
fails:Pattern matching checks patterns until the first matching
@@ -41,7 +39,6 @@ fails:Pattern matching Array pattern does not match object without #deconstruct
4139
fails:Pattern matching Array pattern raises TypeError if #deconstruct method does not return array
4240
fails:Pattern matching Array pattern does not match object if elements of array returned by #deconstruct method does not match elements in pattern
4341
fails:Pattern matching Array pattern binds variables
44-
fails:Pattern matching Array pattern binds variable even if patter matches only partially
4542
fails:Pattern matching Array pattern supports splat operator *rest
4643
fails:Pattern matching Array pattern does not match partially by default
4744
fails:Pattern matching Array pattern does match partially from the array beginning if list + , syntax used
@@ -66,7 +63,6 @@ fails:Pattern matching Hash pattern passes keys specified in pattern as argument
6663
fails:Pattern matching Hash pattern passes keys specified in pattern to #deconstruct_keys method if pattern contains double splat operator **
6764
fails:Pattern matching Hash pattern passes nil to #deconstruct_keys method if pattern contains double splat operator **rest
6865
fails:Pattern matching Hash pattern binds variables
69-
fails:Pattern matching Hash pattern binds variable even if pattern matches only partially
7066
fails:Pattern matching Hash pattern supports double splat operator **rest
7167
fails:Pattern matching Hash pattern treats **nil like there should not be any other keys in a matched Hash
7268
fails:Pattern matching Hash pattern can match partially

spec/tags/language/rescue_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
fails:The rescue keyword allows 'rescue' in method arguments
21
fails:The rescue keyword raises SyntaxError when else is used without rescue and ensure
32
fails:The rescue keyword inline form rescues with multiple assignment

spec/tags/language/return_tags.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
fails:The return keyword in a Thread raises a LocalJumpError if used to exit a thread
22
slow:The return keyword at top level stops file execution
33
slow:The return keyword at top level within a begin fires ensure block before returning
4-
slow:The return keyword at top level return with argument does not affect exit status
5-
fails:The return keyword at top level within a class is allowed
6-
fails:The return keyword at top level file loading stops file loading and execution
7-
fails:The return keyword at top level file requiring stops file loading and execution
8-
fails:The return keyword at top level return with argument does not affect exit status
9-
fails:The return keyword at top level within a block within a class is allowed
10-
fails:The return keyword at top level within a class raises a SyntaxError
11-
fails(escapes the interpreter):The return keyword at top level within a block within a class is not allowed
124
slow:The return keyword at top level return with argument warns but does not affect exit status
135
fails:The return keyword at top level return with argument warns but does not affect exit status

spec/tags/language/string_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ slow:Ruby String literals with a magic frozen comment produce the same object fo
33
slow:Ruby String literals with a magic frozen comment produce the same object for literals with the same content in different files
44
slow:Ruby String literals with a magic frozen comment produce different objects for literals with the same content in different files if the other file doesn't have the comment
55
slow:Ruby String literals with a magic frozen comment produce different objects for literals with the same content in different files if they have different encodings
6-
fails:Ruby character strings don't get confused by partial interpolation character sequences
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. This
3+
* code is released under a tri EPL/GPL/LGPL license. You can use it,
4+
* redistribute it and/or modify it under the terms of the:
5+
*
6+
* Eclipse Public License version 2.0, or
7+
* GNU General Public License version 2, or
8+
* GNU Lesser General Public License version 2.1.
9+
*/
10+
package org.truffleruby.language.control;
11+
12+
import org.truffleruby.language.RubyContextSourceNode;
13+
import org.truffleruby.language.RubyNode;
14+
15+
import com.oracle.truffle.api.frame.VirtualFrame;
16+
17+
public class InvalidReturnNode extends RubyContextSourceNode {
18+
19+
@Child public RubyNode value;
20+
21+
public InvalidReturnNode(RubyNode value) {
22+
this.value = value;
23+
}
24+
25+
@Override
26+
public Object execute(VirtualFrame frame) {
27+
value.doExecuteVoid(frame);
28+
throw new RaiseException(getContext(), coreExceptions().unexpectedReturn(this));
29+
}
30+
31+
}

0 commit comments

Comments
 (0)