From ec2e223b9a82929638353a505f4923ce0439cf69 Mon Sep 17 00:00:00 2001 From: Stefan Koch Date: Thu, 26 Oct 2017 18:02:44 +0200 Subject: [PATCH] fix bug in --space_before_function_parameters --- src/dfmt/formatter.d | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index cd4ec83..41e23e7 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -281,8 +281,8 @@ private: { writeToken(); if (index < tokens.length && (currentIs(tok!"identifier") - || ( ( isBasicType(peekBack().type) || peekBackIs(tok!"identifier") ) && - currentIs(tok!("(")) && config.dfmt_space_before_function_parameters) + || ( index < 1 && ( isBasicType(peekBack(2).type) || peekBack2Is(tok!"identifier") ) && + currentIs(tok!("(")) && config.dfmt_space_before_function_parameters ) || isBasicType(current.type) || currentIs(tok!"@") || currentIs(tok!"if") || isNumberLiteral(tokens[index].type) || (inAsm && peekBack2Is(tok!";") && currentIs(tok!"[")))) @@ -1576,10 +1576,13 @@ const pure @safe @nogc: return tokens[index]; } - const(Token) peekBack() nothrow + const(Token) peekBack(uint distance = 1) nothrow { - assert(index > 0); - return tokens[index - 1]; + if (index < distance) + { + assert(0, "Trying to peek before the first token"); + } + return tokens[index - distance]; } bool peekBackIsLiteralOrIdent() nothrow