diff --git a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RCommand.java b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RCommand.java
index 4fd6c52a0fe1a3ca796fd341fa911297dbc81f74..64e03cca267097f2d160f8641fdf7d38d9fc6e5c 100644
--- a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RCommand.java
+++ b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RCommand.java
@@ -285,7 +285,8 @@ public class RCommand {
                         try {
                             Source src;
                             if (srcFile != null) {
-                                src = Source.newBuilder("R", sb.toString(), srcFile.getName() + "#" + startLine).interactive(true).uri(srcFile.toURI()).buildLiteral();
+                                int endLine = consoleHandler.getCurrentLineIndex();
+                                src = Source.newBuilder("R", sb.toString(), srcFile.getName() + "#" + startLine + "-" + endLine).interactive(true).uri(srcFile.toURI()).buildLiteral();
                             } else {
                                 src = Source.newBuilder("R", sb.toString(), "<REPL>").interactive(true).buildLiteral();
                             }
diff --git a/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/R.g b/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/R.g
index e593e086e1920ab943d5fc60fc29ed89297f32f0..21326517ababa0af8da39f71ae6c33dadeac4c8d 100644
--- a/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/R.g
+++ b/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/R.g
@@ -91,41 +91,53 @@ import com.oracle.truffle.r.runtime.RError;
     }
     
     private Source createFullSource(Source original) {
-        String originalName = original.getName();
+            String originalName = original.getName();
 
-        // check if source name is like 'path/to/source.R#45-54'
-        int hash_idx = originalName.lastIndexOf("#");
-        if (hash_idx == -1) {
-            return original;
-        }
+            // check if source name is like 'path/to/source.R#45-54'
+            int hash_idx = originalName.lastIndexOf("#");
+            if (hash_idx == -1) {
+                return original;
+            }
 
-        String fileName = originalName.substring(0, hash_idx);
-        String lineRange = originalName.substring(hash_idx + 1);
+            String fileName = originalName.substring(0, hash_idx);
+            String lineRange = originalName.substring(hash_idx + 1);
+
+            try {
+                // check for line range, e.g. '45-54'
+                int startLine = -1;
+                int endLine = -1;
+                int dashIdx = lineRange.indexOf('-');
+                if (dashIdx != -1) {
+                    startLine = Integer.parseInt(lineRange.substring(0, dashIdx));
+                    endLine = Integer.parseInt(lineRange.substring(dashIdx + 1));
+                } else {
+                    startLine = Integer.parseInt(lineRange);
+                    endLine = startLine;
+                }
+                Builder<IOException, RuntimeException, RuntimeException> newBuilder = Source.newBuilder(new File(fileName));
+                if (original.isInteractive()) {
+                    newBuilder.interactive();
+                }
+                Source fullSource = newBuilder.build();
 
-        try {
-            // check for line range, e.g. '45-54'
-            int startLine = -1;
-            int endLine = -1;
-            int dashIdx = lineRange.indexOf('-');
-            if (dashIdx != -1) {
-                startLine = Integer.parseInt(lineRange.substring(0, dashIdx));
-                endLine = Integer.parseInt(lineRange.substring(dashIdx + 1));
-            } else {
-                startLine = Integer.parseInt(lineRange);
-            }
-            Builder<IOException, RuntimeException, RuntimeException> newBuilder = Source.newBuilder(new File(fileName));
-            if (original.isInteractive()) {
-                newBuilder.interactive();
+                // verify to avoid accidentally matching file names
+                for (int i = 0; i < endLine - startLine + 1; i++) {
+                    if (!original.getCharacters(i + 1).equals(fullSource.getCharacters(startLine + i))) {
+                        return original;
+                    }
+                }
+
+                fileStartOffset = -fullSource.getLineStartOffset(startLine);
+                return fullSource;
+            } catch (NumberFormatException e) {
+            	// invalid line number
+            } catch (IllegalArgumentException e) {
+            	// file name is accidentally named in the expected scheme
+            } catch (IOException e) {
+            } catch (RuntimeException e) {
             }
-            Source fullSource = newBuilder.build();
-            fileStartOffset = -fullSource.getLineStartOffset(startLine);
-            return fullSource;
-        } catch (NumberFormatException e) {
-        } catch (IOException e) {
-        } catch (RuntimeException e) {
+            return original;
         }
-        return original;
-    }
     
     /**
      * Helper function that returns the last parsed token, usually used for building source sections.