Skip to content

Commit 102bb5b

Browse files
authored
Allow modifier string arguments containing "{" (#480)
1 parent 25eb6c4 commit 102bb5b

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

lib/registrar.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,28 @@ class Registrar {
9494
* @param {Object} expression AST node
9595
*/
9696
functionDeclaration(contract, expression) {
97-
const startContract = contract.instrumented.slice(0, expression.range[0]);
97+
let start = 0;
98+
99+
// It's possible functions will have modifiers that take string args
100+
// which contains an open curly brace. Skip ahead...
101+
if (expression.modifiers && expression.modifiers.length){
102+
for (let modifier of expression.modifiers ){
103+
if (modifier.range[1] > start){
104+
start = modifier.range[1];
105+
}
106+
}
107+
} else {
108+
start = expression.range[0];
109+
}
110+
111+
const startContract = contract.instrumented.slice(0, start);
98112
const startline = ( startContract.match(/\n/g) || [] ).length + 1;
99-
const startcol = expression.range[0] - startContract.lastIndexOf('\n') - 1;
113+
const startcol = start - startContract.lastIndexOf('\n') - 1;
100114

101-
const endlineDelta = contract.instrumented.slice(expression.range[0]).indexOf('{');
115+
const endlineDelta = contract.instrumented.slice(start).indexOf('{');
102116
const functionDefinition = contract.instrumented.slice(
103-
expression.range[0],
104-
expression.range[0] + endlineDelta
117+
start,
118+
start + endlineDelta
105119
);
106120
const endline = startline + (functionDefinition.match(/\n/g) || []).length;
107121
const endcol = functionDefinition.length - functionDefinition.lastIndexOf('\n');
@@ -118,7 +132,7 @@ class Registrar {
118132

119133
this._createInjectionPoint(
120134
contract,
121-
expression.range[0] + endlineDelta + 1,
135+
start + endlineDelta + 1,
122136
{
123137
type: 'injectFunction',
124138
fnId: contract.fnId,

test/sources/solidity/contracts/statements/interpolation.sol

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ contract Interpolated {
66
}
77
}
88

9-
contract Test is Interpolated("abc{defg}"){
9+
contract TestA is Interpolated("abc{defg}"){
1010
function a(uint x) public {
1111
uint y = x;
1212
}
1313
}
14+
15+
contract TestB is Interpolated {
16+
constructor(uint x) public Interpolated("abc{defg}") {
17+
uint y = x;
18+
}
19+
}

test/units/statements.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('generic statements', () => {
2323
util.report(info.solcOutput.errors);
2424
})
2525

26-
it('should compile a base contract contructor with a string arg containing "{"', ()=> {
26+
it('should compile base contract contructors with string args containing "{"', ()=> {
2727
const info = util.instrumentAndCompile('statements/interpolation');
2828
util.report(info.solcOutput.errors);
2929
})

0 commit comments

Comments
 (0)