Repository: hylo-lang/hylo (swift)

Issue:
unterminated string/comment source locations seem a little strange
https://github.com/hylo-lang/hylo/blob/82808ee24dfcee86703949f07e4bf557f914db0b/Sources/FrontEnd/Parse/Parser%2BDiagnostics.swift#L45

Do we really ever want to report where an unterminated thing ends?  Won't that always be the end of the file?  Wouldn't it be more useful to point the user to where it began?

Pull request description:
Fixes #1304

Patch:
diff --git a/Sources/FrontEnd/Parse/Parser+Diagnostics.swift b/Sources/FrontEnd/Parse/Parser+Diagnostics.swift
index 238127acd..05b0dba57 100644
--- a/Sources/FrontEnd/Parse/Parser+Diagnostics.swift
+++ b/Sources/FrontEnd/Parse/Parser+Diagnostics.swift
@@ -42,12 +42,12 @@ extension Diagnostic {
     .error("unexpected token '\(token.kind)'", at: token.site)
   }
 
-  static func error(unterminatedCommentEndingAt endLocation: SourcePosition) -> Diagnostic {
-    .error("unterminated comment", at: endLocation ..< endLocation)
+  static func error(unterminatedCommentStartingAt p: SourcePosition) -> Diagnostic {
+    .error("unterminated comment", at: p ..< p)
   }
 
-  static func error(unterminatedStringEndingAt endLocation: SourcePosition) -> Diagnostic {
-    .error("unterminated string", at: endLocation ..< endLocation)
+  static func error(unterminatedStringStartingAt p: SourcePosition) -> Diagnostic {
+    .error("unterminated string", at: p ..< p)
   }
 
   static func error(duplicateAccessModifier m: SourceRepresentable<AccessModifier>) -> Diagnostic {
diff --git a/Sources/FrontEnd/Parse/Parser.swift b/Sources/FrontEnd/Parse/Parser.swift
index d4673987e..3e25d2252 100644
--- a/Sources/FrontEnd/Parse/Parser.swift
+++ b/Sources/FrontEnd/Parse/Parser.swift
@@ -66,13 +66,13 @@ public enum Parser {
       case .unterminatedBlockComment:
         // Nothing to parse after an unterminated block comment.
         state.diagnostics.insert(
-          .error(unterminatedCommentEndingAt: head.site.last() ?? head.site.first()))
+          .error(unterminatedCommentStartingAt: head.site.first()))
         break
 
       case .unterminatedString:
         // Nothing to parse after an unterminated string.
         state.diagnostics.insert(
-          .error(unterminatedStringEndingAt: head.site.last() ?? head.site.first()))
+          .error(unterminatedStringStartingAt: head.site.first()))
         break
 
       default:


Test patch:
diff --git a/Tests/HyloTests/TestCases/Parsing/UnterminatedNestedComment.hylo b/Tests/HyloTests/TestCases/Parsing/UnterminatedNestedComment.hylo
index 3d5ee207a..0a3a98272 100644
--- a/Tests/HyloTests/TestCases/Parsing/UnterminatedNestedComment.hylo
+++ b/Tests/HyloTests/TestCases/Parsing/UnterminatedNestedComment.hylo
@@ -1,5 +1,5 @@
 //- parse expecting: failure
 
-//! @+2 diagnostic unterminated comment
+//! @+1 diagnostic unterminated comment
 /* This block never ends
   /* even if it contains a nested block */