File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -155,7 +155,9 @@ case object Help extends Command {
155155
156156object ParseResult {
157157
158- @ sharable private val CommandExtract = """ (:[\S]+)\s*(.*)""" .r
158+ // Commands must start with ":" followed by a letter (e.g. :help, :load)
159+ // This ensures operators like :: or :+ are treated as Scala code, not commands
160+ @ sharable private val CommandExtract = """ (:[a-zA-Z]\S*)\s*(.*)""" .r
159161
160162 private def parseStats (using Context ): List [untpd.Tree ] = {
161163 val parser = new Parser (ctx.source)
Original file line number Diff line number Diff line change @@ -520,6 +520,28 @@ class ReplCompilerTests extends ReplTest:
520520 @ Test def `i22844b regression colon arrow eol` : Unit = contextually :
521521 assertTrue(ParseResult .isIncomplete(" List(42).map: x =>" ))
522522
523+ // i24142: Colon operator at line beginning should be treated as Scala code, not REPL command
524+ @ Test def `i24142 cons operator` : Unit = initially :
525+ run(" ::(1, Nil)" )
526+ assertEquals(" val res0: ::[Int] = List(1)" , storedOutput().trim)
527+
528+ @ Test def `i24142 symbolic identifier starting with colon` : Unit = initially :
529+ // Test a custom identifier starting with :
530+ run(" val `:test` = 42" )
531+ assertEquals(" val :test: Int = 42" , storedOutput().trim)
532+
533+ @ Test def `i24142 colon as infix` : Unit = initially :
534+ run(" 1 :: 2 :: Nil" )
535+ assertEquals(" val res0: List[Int] = List(1, 2)" , storedOutput().trim)
536+
537+ @ Test def `i24142 commands still work` : Unit = initially :
538+ run(" :help" )
539+ assertTrue(storedOutput().contains(" The REPL has several commands available" ))
540+
541+ @ Test def `i24142 abbreviated commands still work` : Unit = initially :
542+ run(" :he" )
543+ assertTrue(storedOutput().contains(" The REPL has several commands available" ))
544+
523545object ReplCompilerTests :
524546
525547 private val pattern = Pattern .compile(" \\ r[\\ n]?|\\ n" );
You can’t perform that action at this time.
0 commit comments