File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -131,11 +131,13 @@ void Parser::fetchSourceLocationFromComment()
131
131
m_locationOverride = SourceLocation{};
132
132
if (!sourceIndex || !start || !end)
133
133
m_errorReporter.syntaxError (6367_error, commentLocation, " Invalid value in source location mapping. Could not parse location specification." );
134
- else if (!((start < 0 && end < 0 ) || (start >= 0 && *start <= *end)))
134
+ else if (!((* start < 0 && * end < 0 ) || (* start >= 0 && *start <= *end)))
135
135
m_errorReporter.syntaxError (5798_error, commentLocation, " Invalid value in source location mapping. Start offset larger than end offset." );
136
+ else if (sourceIndex == -1 && (0 <= *start && *start <= *end)) // Use source index -1 to indicate original source.
137
+ m_locationOverride = SourceLocation{*start, *end, ParserBase::currentLocation ().source };
136
138
else if (!(sourceIndex >= 0 && m_charStreamMap->count (static_cast <unsigned >(*sourceIndex))))
137
139
m_errorReporter.syntaxError (2674_error, commentLocation, " Invalid source mapping. Source index not defined via @use-src." );
138
- else if (sourceIndex >= 0 )
140
+ else
139
141
{
140
142
shared_ptr<CharStream> charStream = m_charStreamMap->at (static_cast <unsigned >(*sourceIndex));
141
143
solAssert (charStream, " " );
Original file line number Diff line number Diff line change @@ -556,6 +556,28 @@ BOOST_AUTO_TEST_CASE(customSourceLocations_ensure_last_match)
556
556
CHECK_LOCATION (varDecl.debugData ->location , sourceText, 30 , 40 );
557
557
}
558
558
559
+ BOOST_AUTO_TEST_CASE (customSourceLocations_reference_original_sloc)
560
+ {
561
+ ErrorList errorList;
562
+ ErrorReporter reporter (errorList);
563
+ auto const sourceText = R"(
564
+ /// @src 1:2:3
565
+ {
566
+ /// @src -1:10:20
567
+ let x:bool := true
568
+ }
569
+ )" ;
570
+ EVMDialectTyped const & dialect = EVMDialectTyped::instance (EVMVersion{});
571
+ shared_ptr<Block> result = parse (sourceText, dialect, reporter);
572
+ BOOST_REQUIRE (!!result);
573
+ BOOST_REQUIRE (holds_alternative<VariableDeclaration>(result->statements .at (0 )));
574
+ VariableDeclaration const & varDecl = get<VariableDeclaration>(result->statements .at (0 ));
575
+
576
+ // -1 points to original source code, which in this case is `sourceText` (which is also
577
+ // available via `0`, that's why the first @src is set to `1` instead.)
578
+ CHECK_LOCATION (varDecl.debugData ->location , sourceText, 10 , 20 );
579
+ }
580
+
559
581
BOOST_AUTO_TEST_SUITE_END ()
560
582
561
583
} // end namespaces
You can’t perform that action at this time.
0 commit comments