Repository: sqlfluff/sqlfluff

Issue:
Exception during linting: "Applying rule L016 threw an Exception: Fixes must provide an anchor."
-- If this is a parsing or linting issue, please include a minimal SQL example which reproduces the issue, along with the `sqlfluff parse` output, `sqlfluff lint` output and `sqlfluff fix` output when relevant. Finally, please add any labels that are related to the issue before submitting so that it can be addressed easily! --

## Expected Behaviour

`sqlfluff lint` should run without reporting exceptions.

## Observed Behaviour

Saw this output:
```
CRITICAL   [L016] Applying rule L016 threw an Exception: Fixes must provide an anchor.
Traceback (most recent call last):
  File "/Users/bhart/dev/sqlfluff/src/sqlfluff/core/rules/base.py", line 310, in crawl
    templated_file=templated_file,
  File "/Users/bhart/dev/sqlfluff/src/sqlfluff/rules/L016.py", line 450, in _eval
    fixes = self._eval_line_for_breaks(this_line)
  File "/Users/bhart/dev/sqlfluff/src/sqlfluff/rules/L016.py", line 351, in _eval_line_for_breaks
    segments, indent_section, self, indent
  File "/Users/bhart/dev/sqlfluff/src/sqlfluff/rules/L016.py", line 165, in generate_fixes_to_coerce
    WhitespaceSegment(new_indent),
  File "/Users/bhart/dev/sqlfluff/src/sqlfluff/core/rules/base.py", line 117, in __init__
    raise ValueError("Fixes must provide an anchor.")
ValueError: Fixes must provide an anchor.
```
## Steps to Reproduce

Run `sqlfluff lint` on this  SQL file:
```
CREATE OR REPLACE MODEL
  `{{project}}.{{dataset}}.paid_propensity_gbm` OPTIONS(model_type='BOOSTED_TREE_REGRESSOR',
    input_label_cols= ['convert']) AS

   select    convert, days_since_activity, index_age , list_size_modified, country_modified, ecomm_level, pro, mandrill,sent_email from
`{{project}}.{{dataset}}.user_starts_and_paid_with_active`
 where rn < 0.8
```

## Version
Include the output of `sqlfluff --version` along with your Python version
SQLFluff: 0.5.4
Python: 3.7.3

## Configuration
```
[sqlfluff]
verbose = 0
nocolor = False
dialect = bigquery
templater = jinja
rules = None
exclude_rules = L029,L031,L032,L034
recurse = 0

[sqlfluff:templater:jinja:macros]

# Some rules can be configured directly from the config common to other rules.
[sqlfluff:rules]
tab_space_size = 4
max_line_length = 120

# Some rules have their own specific config.
[sqlfluff:rules:L010]
capitalisation_policy = consistent

[sqlfluff:rules:L014]
capitalisation_policy = consistent

[sqlfluff:rules:L030]
capitalisation_policy = consistent

# Settings in this section will be provided to SQL templates during the SQL
# formatting/linting process. Generally, the exact values don't matter as long
# as they result in valid SQL syntax when substituted in the file.
[sqlfluff:templater:jinja:context]
gcp_project=gcp_project
project=gcp_project
dataset=dataset
user_filter=
date_filter=
```



Discussion:

Patch:
diff --git a/src/sqlfluff/core/parser/markers.py b/src/sqlfluff/core/parser/markers.py
index 11e3758da..74d491713 100644
--- a/src/sqlfluff/core/parser/markers.py
+++ b/src/sqlfluff/core/parser/markers.py
@@ -165,13 +165,17 @@ class PositionMarker:
 
     @staticmethod
     def infer_next_position(raw: str, line_no: int, line_pos: int) -> Tuple[int, int]:
-        """Using the raw string provided to infer the position of the next."""
+        """Using the raw string provided to infer the position of the next.
+
+        NB: Line position in 1-indexed.
+        """
+        # No content?
         if not raw:
             return line_no, line_pos
         split = raw.split("\n")
         return (
             line_no + len(split) - 1,
-            line_pos + len(raw) if len(split) == 1 else len(split[-1]),
+            line_pos + len(raw) if len(split) == 1 else len(split[-1]) + 1,
         )
 
     def with_working_position(self, line_no: int, line_pos: int):
diff --git a/src/sqlfluff/core/parser/segments/base.py b/src/sqlfluff/core/parser/segments/base.py
index 1d379e761..a9ffc2294 100644
--- a/src/sqlfluff/core/parser/segments/base.py
+++ b/src/sqlfluff/core/parser/segments/base.py
@@ -526,7 +526,7 @@ class BaseSegment:
 
     def get_start_loc(self):
         """Get a location tuple at the start of this segment."""
-        return self.pos_marker.working_loc()
+        return self.pos_marker.working_loc
 
     def get_end_loc(self):
         """Get a location tuple at the end of this segment."""


Test patch:
diff --git a/test/core/parser/markers_test.py b/test/core/parser/markers_test.py
index 0d2ccc37f..41be3ff02 100644
--- a/test/core/parser/markers_test.py
+++ b/test/core/parser/markers_test.py
@@ -11,10 +11,11 @@ from sqlfluff.core.parser.markers import PositionMarker
     [
         ("fsaljk", (0, 0), (0, 6)),
         ("", (2, 2), (2, 2)),
-        ("\n", (2, 2), (3, 0)),
-        ("boo\n", (2, 2), (3, 0)),
-        ("boo\nfoo", (2, 2), (3, 3)),
-        ("\nfoo", (2, 2), (3, 3)),
+        # NB: 1 indexed, not 0 indexed.
+        ("\n", (2, 2), (3, 1)),
+        ("boo\n", (2, 2), (3, 1)),
+        ("boo\nfoo", (2, 2), (3, 4)),
+        ("\nfoo", (2, 2), (3, 4)),
     ],
 )
 def test_markers__infer_next_position(raw, start_pos, end_pos):