diff --git a/CHANGELOG b/CHANGELOG
index 83b26c9..698e6ea 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -6,6 +6,10 @@
 ### Added
 - Added `INDENT_BLANK_LINES` knob to select whether the blank lines are empty
   or indented consistently with the current block.
+### Fixed
+- Correctly determine if a scope is the last in line. It avoids a wrong
+  computation of the line end when determining if it must split after the
+  opening bracket with `DEDENT_CLOSING_BRACKETS` enabled.
 
 ## [0.24.0] 2018-09-07
 ### Added
diff --git a/yapf/yapflib/format_decision_state.py b/yapf/yapflib/format_decision_state.py
index cd6a729..40b4571 100644
--- a/yapf/yapflib/format_decision_state.py
+++ b/yapf/yapflib/format_decision_state.py
@@ -930,6 +930,7 @@ def _IsFunctionDefinition(current):
 
 
 def _IsLastScopeInLine(current):
+  current = current.matching_bracket
   while current:
     current = current.next_token
     if current and current.OpensScope():

diff --git a/yapftests/reformatter_basic_test.py b/yapftests/reformatter_basic_test.py
index 57a45d6..3de71a8 100644
--- a/yapftests/reformatter_basic_test.py
+++ b/yapftests/reformatter_basic_test.py
@@ -2558,6 +2558,37 @@ x = [1, 2, 3, 4, 5, 6, 7,]
     finally:
       style.SetGlobalStyle(style.CreateChromiumStyle())
 
+  def testDedentClosingBracketsWithTypeAnnotationExceedingLineLength(self):
+    try:
+      style.SetGlobalStyle(
+          style.CreateStyleFromConfig('{based_on_style: chromium,'
+                                      ' dedent_closing_brackets: True}'))
+      unformatted_code = textwrap.dedent("""\
+                def function(first_argument_xxxxxxxxxxxxxxxx=(0,), second_argument=None) -> None:
+                  pass
+
+
+                def function(first_argument_xxxxxxxxxxxxxxxxxxxxxxx=(0,), second_argument=None) -> None:
+                  pass
+                """)
+      expected_formatted_code = textwrap.dedent("""\
+                def function(
+                    first_argument_xxxxxxxxxxxxxxxx=(0,), second_argument=None
+                ) -> None:
+                  pass
+
+
+                def function(
+                    first_argument_xxxxxxxxxxxxxxxxxxxxxxx=(0,), second_argument=None
+                ) -> None:
+                  pass
+                """)
+      uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+      self.assertCodeEqual(expected_formatted_code,
+                           reformatter.Reformat(uwlines))
+    finally:
+      style.SetGlobalStyle(style.CreateChromiumStyle())
+
 
 if __name__ == '__main__':
   unittest.main()

DEDENT_CLOSING_BRACKETS does not seem to work if arguments fit in line
I am getting somewhat inconsistent formatting on code like this:

```python
def long_function_name(argument1: Tuple[str, int], argument2: List[str]) -> Iterator[str]:
    pass

def ever_longer_function_name(argument1: Tuple[str, int], argument2: List[str]) -> Iterator[str]:
    pass
```

My `setup.cfg`:
```ini
[yapf]
based_on_style = pep8
coalesce_brackets = True
dedent_closing_brackets = True
split_penalty_after_opening_bracket = 0
split_before_first_argument = true
```

The result is this:
```python
def long_function_name(argument1: Tuple[str, int],
                       argument2: List[str]) -> Iterator[str]:
    pass


def ever_longer_function_name(
        argument1: Tuple[str, int], argument2: List[str]
) -> Iterator[str]:
    pass
```

However, i would prefer the second style for the first example as well. I was expecting the `split_before_first_argument` option to have exactly that effect, but it does not seem to work.

With type annotations, the function signatures can get significant length other than their arguments. so this happens quite frequently in my code base. This issue seems to happen if the arguments fit in one line, but the full signature does not. If the arguments are longer than one line, it works fine.

I am using version 0.14.0.
yapftests/reformatter_basic_test.py::BasicReformatterTest::testDedentClosingBracketsWithTypeAnnotationExceedingLineLength
yapftests/reformatter_basic_test.py::BasicReformatterTest::testArgsAndKwargsFormatting yapftests/reformatter_basic_test.py::BasicReformatterTest::testBinaryOperators yapftests/reformatter_basic_test.py::BasicReformatterTest::testBlankLineBeforeClassDocstring yapftests/reformatter_basic_test.py::BasicReformatterTest::testBlankLineBeforeModuleDocstring yapftests/reformatter_basic_test.py::BasicReformatterTest::testBlankLinesAtEndOfFile yapftests/reformatter_basic_test.py::BasicReformatterTest::testBlankLinesBeforeDecorators yapftests/reformatter_basic_test.py::BasicReformatterTest::testBlankLinesBeforeFunctionsNotInColumnZero yapftests/reformatter_basic_test.py::BasicReformatterTest::testClosingBracketIndent yapftests/reformatter_basic_test.py::BasicReformatterTest::testClosingBracketsInlinedInCall yapftests/reformatter_basic_test.py::BasicReformatterTest::testCoalesceBracketsOnDict yapftests/reformatter_basic_test.py::BasicReformatterTest::testCommentBeforeFuncDef yapftests/reformatter_basic_test.py::BasicReformatterTest::testCommentBetweenDecorators yapftests/reformatter_basic_test.py::BasicReformatterTest::testCommentColumnLimitOverflow yapftests/reformatter_basic_test.py::BasicReformatterTest::testComments yapftests/reformatter_basic_test.py::BasicReformatterTest::testCommentsInDataLiteral yapftests/reformatter_basic_test.py::BasicReformatterTest::testCommentsWithContinuationMarkers yapftests/reformatter_basic_test.py::BasicReformatterTest::testCommentsWithTrailingSpaces yapftests/reformatter_basic_test.py::BasicReformatterTest::testComprehensionForAndIf yapftests/reformatter_basic_test.py::BasicReformatterTest::testContiguousList yapftests/reformatter_basic_test.py::BasicReformatterTest::testContinuationIndent yapftests/reformatter_basic_test.py::BasicReformatterTest::testContinuationMarkerAfterStringWithContinuation yapftests/reformatter_basic_test.py::BasicReformatterTest::testContinuationMarkers yapftests/reformatter_basic_test.py::BasicReformatterTest::testContinuationSpaceRetention yapftests/reformatter_basic_test.py::BasicReformatterTest::testDictSetGenerator yapftests/reformatter_basic_test.py::BasicReformatterTest::testDictionaryElementsOnOneLine yapftests/reformatter_basic_test.py::BasicReformatterTest::testDictionaryMakerFormatting yapftests/reformatter_basic_test.py::BasicReformatterTest::testDictionaryOnOwnLine yapftests/reformatter_basic_test.py::BasicReformatterTest::testDictionaryValuesOnOwnLines yapftests/reformatter_basic_test.py::BasicReformatterTest::testDisableEndingCommaHeuristic yapftests/reformatter_basic_test.py::BasicReformatterTest::testDocstringAndMultilineComment yapftests/reformatter_basic_test.py::BasicReformatterTest::testDocstrings yapftests/reformatter_basic_test.py::BasicReformatterTest::testDontAddBlankLineAfterMultilineString yapftests/reformatter_basic_test.py::BasicReformatterTest::testDontSplitKeywordValueArguments yapftests/reformatter_basic_test.py::BasicReformatterTest::testEllipses yapftests/reformatter_basic_test.py::BasicReformatterTest::testEmptyContainers yapftests/reformatter_basic_test.py::BasicReformatterTest::testEndingComment yapftests/reformatter_basic_test.py::BasicReformatterTest::testEndingWhitespaceAfterSimpleStatement yapftests/reformatter_basic_test.py::BasicReformatterTest::testExcessCharacters yapftests/reformatter_basic_test.py::BasicReformatterTest::testExcessLineCountWithDefaultKeywords yapftests/reformatter_basic_test.py::BasicReformatterTest::testExpressionPenalties yapftests/reformatter_basic_test.py::BasicReformatterTest::testFormattingListComprehensions yapftests/reformatter_basic_test.py::BasicReformatterTest::testFunctionCallArguments yapftests/reformatter_basic_test.py::BasicReformatterTest::testFunctionCallContinuationLine yapftests/reformatter_basic_test.py::BasicReformatterTest::testFunctionCallInDict yapftests/reformatter_basic_test.py::BasicReformatterTest::testFunctionCallInNestedDict yapftests/reformatter_basic_test.py::BasicReformatterTest::testI18n yapftests/reformatter_basic_test.py::BasicReformatterTest::testI18nCommentsInDataLiteral yapftests/reformatter_basic_test.py::BasicReformatterTest::testI18nNonFormatting yapftests/reformatter_basic_test.py::BasicReformatterTest::testIfConditionalParens yapftests/reformatter_basic_test.py::BasicReformatterTest::testIfExpressionWithFunctionCall yapftests/reformatter_basic_test.py::BasicReformatterTest::testImportAsList yapftests/reformatter_basic_test.py::BasicReformatterTest::testIndentBlankLines yapftests/reformatter_basic_test.py::BasicReformatterTest::testLineDepthOfSingleLineStatement yapftests/reformatter_basic_test.py::BasicReformatterTest::testLineWrapInForExpression yapftests/reformatter_basic_test.py::BasicReformatterTest::testListComprehension yapftests/reformatter_basic_test.py::BasicReformatterTest::testListComprehensionPreferNoBreakForTrivialExpression yapftests/reformatter_basic_test.py::BasicReformatterTest::testListComprehensionPreferOneLine yapftests/reformatter_basic_test.py::BasicReformatterTest::testListComprehensionPreferOneLineOverArithmeticSplit yapftests/reformatter_basic_test.py::BasicReformatterTest::testListComprehensionPreferThreeLinesForLineWrap yapftests/reformatter_basic_test.py::BasicReformatterTest::testListWithFunctionCalls yapftests/reformatter_basic_test.py::BasicReformatterTest::testMatchingParenSplittingMatching yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultilineComment yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultilineCommentReformatted yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultilineDictionaryKeys yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultilineDocstringAndMultilineComment yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultilineLambdas yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultilineShebang yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultilineString yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultipleContinuationMarkers yapftests/reformatter_basic_test.py::BasicReformatterTest::testMultipleUgliness yapftests/reformatter_basic_test.py::BasicReformatterTest::testNamedAssignNotAtEndOfLine yapftests/reformatter_basic_test.py::BasicReformatterTest::testNestedDictionary yapftests/reformatter_basic_test.py::BasicReformatterTest::testNestedListsInDictionary yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoBreakOutsideOfBracket yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoKeywordArgumentBreakage yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoPenaltySplitting yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoQueueSeletionInMiddleOfLine yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSpaceBetweenUnaryOpAndOpeningParen yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSpacesAroundKeywordDefaultValues yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSpacesBetweenOpeningBracketAndStartingOperator yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSpacesBetweenSubscriptsAndCalls yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSplittingAroundTermOperators yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSplittingBeforeEndingSubscriptBracket yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSplittingOnSingleArgument yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSplittingWhenBinPacking yapftests/reformatter_basic_test.py::BasicReformatterTest::testNoSplittingWithinSubscriptList yapftests/reformatter_basic_test.py::BasicReformatterTest::testNotInParams yapftests/reformatter_basic_test.py::BasicReformatterTest::testNotSplittingAfterSubscript yapftests/reformatter_basic_test.py::BasicReformatterTest::testOpeningAndClosingBrackets yapftests/reformatter_basic_test.py::BasicReformatterTest::testOverColumnLimit yapftests/reformatter_basic_test.py::BasicReformatterTest::testPseudoParens yapftests/reformatter_basic_test.py::BasicReformatterTest::testRelativeImportStatements yapftests/reformatter_basic_test.py::BasicReformatterTest::testRelaxArraySubscriptAffinity yapftests/reformatter_basic_test.py::BasicReformatterTest::testSimpleFunctionsWithTrailingComments yapftests/reformatter_basic_test.py::BasicReformatterTest::testSimpleMultilineCode yapftests/reformatter_basic_test.py::BasicReformatterTest::testSimpleMultilineWithComments yapftests/reformatter_basic_test.py::BasicReformatterTest::testSingleComment yapftests/reformatter_basic_test.py::BasicReformatterTest::testSingleLineFunctions yapftests/reformatter_basic_test.py::BasicReformatterTest::testSingleLineList yapftests/reformatter_basic_test.py::BasicReformatterTest::testSpaceAfterNotOperator yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplitAfterComment yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplitListWithComment yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplitListWithInterspersedComments yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplitListWithTerminatingComma yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplitStringsIfSurroundedByParens yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplittingAllArgs yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplittingArgumentsTerminatedByComma yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplittingArraysSensibly yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplittingBeforeFirstArgumentOnCompoundStatement yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplittingBeforeFirstArgumentOnFunctionCall yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplittingBeforeFirstArgumentOnFunctionDefinition yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplittingBeforeFirstElementListArgument yapftests/reformatter_basic_test.py::BasicReformatterTest::testSplittingOneArgumentList yapftests/reformatter_basic_test.py::BasicReformatterTest::testStableDictionaryFormatting yapftests/reformatter_basic_test.py::BasicReformatterTest::testStableInlinedDictionaryFormatting yapftests/reformatter_basic_test.py::BasicReformatterTest::testSubscriptExpression yapftests/reformatter_basic_test.py::BasicReformatterTest::testTrailerOnSingleLine yapftests/reformatter_basic_test.py::BasicReformatterTest::testTrailingCommaAndBracket yapftests/reformatter_basic_test.py::BasicReformatterTest::testTupleCohesion yapftests/reformatter_basic_test.py::BasicReformatterTest::testTupleCommaBeforeLastParen yapftests/reformatter_basic_test.py::BasicReformatterTest::testUnaryNotOperator yapftests/reformatter_basic_test.py::BasicReformatterTest::testUnaryOpInDictionaryValue yapftests/reformatter_basic_test.py::BasicReformatterTest::testUnbreakableNot yapftests/reformatter_basic_test.py::BasicReformatterTest::testUnformattedAfterMultilineString