@@ -2811,6 +2811,134 @@ module M[T < Array[void]]
28112811 assert_equal "a.rbs:1:11...1:19: Syntax error: `instance` type is not allowed in this context, token=`instance` (kINSTANCE)" , ex . message
28122812 end
28132813
2814+ def test_context_syntax_error_lower_bound
2815+ assert_nothing_raised do
2816+ Parser . parse_signature ( <<~SIG )
2817+ class C[T > Array[void]]
2818+ end
2819+ module M[T > Array[void]]
2820+ end
2821+ interface _I[T > Array[void]]
2822+ end
2823+ type a[T > Array[void]] = 1
2824+ SIG
2825+ end
2826+
2827+ ex = assert_raises RBS ::ParsingError do
2828+ Parser . parse_signature ( "class C[T > void] end" )
2829+ end
2830+ assert_equal "a.rbs:1:12...1:16: Syntax error: `void` type is only allowed in return type or generics parameter, token=`void` (kVOID)" , ex . message
2831+
2832+ ex = assert_raises RBS ::ParsingError do
2833+ Parser . parse_signature ( "class C[T > self] end" )
2834+ end
2835+ assert_equal "a.rbs:1:12...1:16: Syntax error: `self` type is not allowed in this context, token=`self` (kSELF)" , ex . message
2836+
2837+ ex = assert_raises RBS ::ParsingError do
2838+ Parser . parse_signature ( "class C[T > class] end" )
2839+ end
2840+ assert_equal "a.rbs:1:12...1:17: Syntax error: `class` type is not allowed in this context, token=`class` (kCLASS)" , ex . message
2841+
2842+ ex = assert_raises RBS ::ParsingError do
2843+ Parser . parse_signature ( "class C[T > instance] end" )
2844+ end
2845+ assert_equal "a.rbs:1:12...1:20: Syntax error: `instance` type is not allowed in this context, token=`instance` (kINSTANCE)" , ex . message
2846+
2847+ ex = assert_raises RBS ::ParsingError do
2848+ Parser . parse_signature ( "module M[T > void] end" )
2849+ end
2850+ assert_equal "a.rbs:1:13...1:17: Syntax error: `void` type is only allowed in return type or generics parameter, token=`void` (kVOID)" , ex . message
2851+
2852+ ex = assert_raises RBS ::ParsingError do
2853+ Parser . parse_signature ( "module M[T > self] end" )
2854+ end
2855+ assert_equal "a.rbs:1:13...1:17: Syntax error: `self` type is not allowed in this context, token=`self` (kSELF)" , ex . message
2856+
2857+ ex = assert_raises RBS ::ParsingError do
2858+ Parser . parse_signature ( "module M[T > class] end" )
2859+ end
2860+ assert_equal "a.rbs:1:13...1:18: Syntax error: `class` type is not allowed in this context, token=`class` (kCLASS)" , ex . message
2861+
2862+ ex = assert_raises RBS ::ParsingError do
2863+ Parser . parse_signature ( "module M[T > instance] end" )
2864+ end
2865+ assert_equal "a.rbs:1:13...1:21: Syntax error: `instance` type is not allowed in this context, token=`instance` (kINSTANCE)" , ex . message
2866+
2867+ ex = assert_raises RBS ::ParsingError do
2868+ Parser . parse_signature ( "interface _I[T > void] end" )
2869+ end
2870+ assert_equal "a.rbs:1:17...1:21: Syntax error: `void` type is only allowed in return type or generics parameter, token=`void` (kVOID)" , ex . message
2871+
2872+ ex = assert_raises RBS ::ParsingError do
2873+ Parser . parse_signature ( "interface _I[T > self] end" )
2874+ end
2875+ assert_equal "a.rbs:1:17...1:21: Syntax error: `self` type is not allowed in this context, token=`self` (kSELF)" , ex . message
2876+
2877+ ex = assert_raises RBS ::ParsingError do
2878+ Parser . parse_signature ( "interface _I[T > class] end" )
2879+ end
2880+ assert_equal "a.rbs:1:17...1:22: Syntax error: `class` type is not allowed in this context, token=`class` (kCLASS)" , ex . message
2881+
2882+ ex = assert_raises RBS ::ParsingError do
2883+ Parser . parse_signature ( "interface _I[T > instance] end" )
2884+ end
2885+ assert_equal "a.rbs:1:17...1:25: Syntax error: `instance` type is not allowed in this context, token=`instance` (kINSTANCE)" , ex . message
2886+
2887+ ex = assert_raises RBS ::ParsingError do
2888+ Parser . parse_signature ( "type a[T > void] = 1" )
2889+ end
2890+ assert_equal "a.rbs:1:11...1:15: Syntax error: `void` type is only allowed in return type or generics parameter, token=`void` (kVOID)" , ex . message
2891+
2892+ ex = assert_raises RBS ::ParsingError do
2893+ Parser . parse_signature ( "type a[T > self] = 1" )
2894+ end
2895+ assert_equal "a.rbs:1:11...1:15: Syntax error: `self` type is not allowed in this context, token=`self` (kSELF)" , ex . message
2896+
2897+ ex = assert_raises RBS ::ParsingError do
2898+ Parser . parse_signature ( "type a[T > class] = 1" )
2899+ end
2900+ assert_equal "a.rbs:1:11...1:16: Syntax error: `class` type is not allowed in this context, token=`class` (kCLASS)" , ex . message
2901+
2902+ ex = assert_raises RBS ::ParsingError do
2903+ Parser . parse_signature ( "type a[T > instance] = 1" )
2904+ end
2905+ assert_equal "a.rbs:1:11...1:19: Syntax error: `instance` type is not allowed in this context, token=`instance` (kINSTANCE)" , ex . message
2906+ end
2907+
2908+ def test_context_syntax_error_upper_and_lower_bound
2909+ assert_nothing_raised do
2910+ Parser . parse_signature ( <<~SIG )
2911+ class C[T < Array[void] > Array[void]]
2912+ end
2913+ module M[T > Array[void] < Array[void]]
2914+ end
2915+ interface _I[T < Array[void] > Array[void]]
2916+ end
2917+ type a[T < Array[void] > Array[void]] = 1
2918+ SIG
2919+ end
2920+
2921+ ex = assert_raises RBS ::ParsingError do
2922+ Parser . parse_signature ( "class C[T < void > Integer] end" )
2923+ end
2924+ assert_equal "a.rbs:1:12...1:16: Syntax error: `void` type is only allowed in return type or generics parameter, token=`void` (kVOID)" , ex . message
2925+
2926+ ex = assert_raises RBS ::ParsingError do
2927+ Parser . parse_signature ( "class C[T > Integer < void] end" )
2928+ end
2929+ assert_equal "a.rbs:1:22...1:26: Syntax error: `void` type is only allowed in return type or generics parameter, token=`void` (kVOID)" , ex . message
2930+
2931+ ex = assert_raises RBS ::ParsingError do
2932+ Parser . parse_signature ( "class C[T < Integer > void] end" )
2933+ end
2934+ assert_equal "a.rbs:1:22...1:26: Syntax error: `void` type is only allowed in return type or generics parameter, token=`void` (kVOID)" , ex . message
2935+
2936+ ex = assert_raises RBS ::ParsingError do
2937+ Parser . parse_signature ( "class C[T > void < Integer] end" )
2938+ end
2939+ assert_equal "a.rbs:1:12...1:16: Syntax error: `void` type is only allowed in return type or generics parameter, token=`void` (kVOID)" , ex . message
2940+ end
2941+
28142942 def test_context_syntax_error_default_type
28152943 assert_nothing_raised do
28162944 Parser . parse_signature ( <<~SIG )
0 commit comments