Skip to content

Commit 8dd1655

Browse files
skipkayhilGQuirino
andcommitted
Fix all 'assigned but unused variable' warnings
- The variables in content_location_parser appear to have been copied from content_disposition_parser but are unused - Ragel seems to always generate a useless testEof variable. The `if false` trick is also used in whitequark/parser@21581a2 to suppress the warning. As mentioned in the parser commit, `if false` will not actually generate instructions and so it has no runtime cost. Co-authored-by: Guilherme Quirino <[email protected]>
1 parent 596f06f commit 8dd1655

23 files changed

+90
-4
lines changed

lib/mail/parsers/address_lists_parser.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33228,6 +33228,10 @@ def self.parse(data)
3322833228
end
3322933229
end
3323033230

33231+
if false
33232+
testEof
33233+
end
33234+
3323133235
if p != eof || cs < 2461
3323233236
raise Mail::Field::IncompleteParseError.new(Mail::AddressList, data, p)
3323333237
end

lib/mail/parsers/address_lists_parser.rl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ module Mail::Parsers
165165
%%write init;
166166
%%write exec;
167167

168+
if false
169+
testEof
170+
end
171+
168172
if p != eof || cs < %%{ write first_final; }%%
169173
raise Mail::Field::IncompleteParseError.new(Mail::AddressList, data, p)
170174
end

lib/mail/parsers/content_disposition_parser.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,10 @@ def self.parse(data)
887887
end
888888
end
889889

890+
if false
891+
testEof
892+
end
893+
890894
if p != eof || cs < 40
891895
raise Mail::Field::IncompleteParseError.new(Mail::ContentDispositionElement, data, p)
892896
end

lib/mail/parsers/content_disposition_parser.rl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ module Mail::Parsers
7575
%%write init;
7676
%%write exec;
7777

78+
if false
79+
testEof
80+
end
81+
7882
if p != eof || cs < %%{ write first_final; }%%
7983
raise Mail::Field::IncompleteParseError.new(Mail::ContentDispositionElement, data, p)
8084
end

lib/mail/parsers/content_location_parser.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def self.parse(data)
588588
return content_location if Mail::Utilities.blank?(data)
589589

590590
# Parser state
591-
disp_type_s = param_attr_s = param_attr = qstr_s = qstr = param_val_s = nil
591+
qstr_s = qstr = param_val_s = nil
592592

593593
# 5.1 Variables Used by Ragel
594594
p = 0
@@ -808,6 +808,10 @@ def self.parse(data)
808808
end
809809
end
810810

811+
if false
812+
testEof
813+
end
814+
811815
if p != eof || cs < 32
812816
raise Mail::Field::IncompleteParseError.new(Mail::ContentLocationElement, data, p)
813817
end

lib/mail/parsers/content_location_parser.rl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module Mail::Parsers
5454
return content_location if Mail::Utilities.blank?(data)
5555

5656
# Parser state
57-
disp_type_s = param_attr_s = param_attr = qstr_s = qstr = param_val_s = nil
57+
qstr_s = qstr = param_val_s = nil
5858

5959
# 5.1 Variables Used by Ragel
6060
p = 0
@@ -64,6 +64,10 @@ module Mail::Parsers
6464
%%write init;
6565
%%write exec;
6666

67+
if false
68+
testEof
69+
end
70+
6771
if p != eof || cs < %%{ write first_final; }%%
6872
raise Mail::Field::IncompleteParseError.new(Mail::ContentLocationElement, data, p)
6973
end

lib/mail/parsers/content_transfer_encoding_parser.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,10 @@ def self.parse(data)
508508
end
509509
end
510510

511+
if false
512+
testEof
513+
end
514+
511515
if p != eof || cs < 21
512516
raise Mail::Field::IncompleteParseError.new(Mail::ContentTransferEncodingElement, data, p)
513517
end

lib/mail/parsers/content_transfer_encoding_parser.rl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ module Mail::Parsers
5757
%%write init;
5858
%%write exec;
5959

60+
if false
61+
testEof
62+
end
63+
6064
if p != eof || cs < %%{ write first_final; }%%
6165
raise Mail::Field::IncompleteParseError.new(Mail::ContentTransferEncodingElement, data, p)
6266
end

lib/mail/parsers/content_type_parser.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,10 @@ def self.parse(data)
10341034
end
10351035
end
10361036

1037+
if false
1038+
testEof
1039+
end
1040+
10371041
if p != eof || cs < 47
10381042
raise Mail::Field::IncompleteParseError.new(Mail::ContentTypeElement, data, p)
10391043
end

lib/mail/parsers/content_type_parser.rl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ module Mail::Parsers
7676
%%write init;
7777
%%write exec;
7878

79+
if false
80+
testEof
81+
end
82+
7983
if p != eof || cs < %%{ write first_final; }%%
8084
raise Mail::Field::IncompleteParseError.new(Mail::ContentTypeElement, data, p)
8185
end

0 commit comments

Comments
 (0)