Error seen on parsing a case class nested in an object definition with Scala 3.
sageserpent-open opened this issue · comments
Gerard Murphy commented
Commit of tree-sitter-scala you tested this on
A code sample showing the error
package com.sageserpent.kineticmerge.core
object Merge:
case class Location(runIndex: Int, locationInRun: String):
end Location
end Merge
Show the error node
compilation_unit (0, 0) - (8, 0)
package_clause (0, 0) - (0, 41)
package (0, 0) - (0, 7) "package"
package_identifier (0, 8) - (0, 41)
identifier (0, 8) - (0, 11) "com"
. (0, 11) - (0, 12) "."
identifier (0, 12) - (0, 23) "sageserpent"
. (0, 23) - (0, 24) "."
identifier (0, 24) - (0, 36) "kineticmerge"
. (0, 36) - (0, 37) "."
identifier (0, 37) - (0, 41) "core"
object_definition (2, 0) - (7, 0)
object (2, 0) - (2, 6) "object"
identifier (2, 7) - (2, 12) "Merge"
template_body (2, 12) - (7, 0)
: (2, 12) - (2, 13) ":"
class_definition (4, 2) - (4, 59)
case (4, 2) - (4, 6) "case"
class (4, 7) - (4, 12) "class"
identifier (4, 13) - (4, 21) "Location"
class_parameters (4, 21) - (4, 59)
( (4, 21) - (4, 22) "("
class_parameter (4, 22) - (4, 35)
identifier (4, 22) - (4, 30) "runIndex"
: (4, 30) - (4, 31) ":"
type_identifier (4, 32) - (4, 35) "Int"
, (4, 35) - (4, 36) ","
class_parameter (4, 37) - (4, 58)
identifier (4, 37) - (4, 50) "locationInRun"
: (4, 50) - (4, 51) ":"
type_identifier (4, 52) - (4, 58) "String"
) (4, 58) - (4, 59) ")"
ERROR (4, 59) - (5, 14)
: (4, 59) - (4, 60) ":"
end (7, 0) - (7, 3) "end"
_end_ident (7, 4) - (7, 9) "Merge"
Incidentally, omitting the end marker for the case class does not avoid the error.
What do you expect the tree to look like
Omitting the colon trailing after the nested case-class definition yields a correct parse, here I have substituted a trailing blank character for the colon...
compilation_unit (0, 0) - (8, 0)
package_clause (0, 0) - (0, 41)
package (0, 0) - (0, 7) "package"
package_identifier (0, 8) - (0, 41)
identifier (0, 8) - (0, 11) "com"
. (0, 11) - (0, 12) "."
identifier (0, 12) - (0, 23) "sageserpent"
. (0, 23) - (0, 24) "."
identifier (0, 24) - (0, 36) "kineticmerge"
. (0, 36) - (0, 37) "."
identifier (0, 37) - (0, 41) "core"
object_definition (2, 0) - (7, 0)
object (2, 0) - (2, 6) "object"
identifier (2, 7) - (2, 12) "Merge"
template_body (2, 12) - (7, 0)
: (2, 12) - (2, 13) ":"
class_definition (4, 2) - (4, 59)
case (4, 2) - (4, 6) "case"
class (4, 7) - (4, 12) "class"
identifier (4, 13) - (4, 21) "Location"
class_parameters (4, 21) - (4, 59)
( (4, 21) - (4, 22) "("
class_parameter (4, 22) - (4, 35)
identifier (4, 22) - (4, 30) "runIndex"
: (4, 30) - (4, 31) ":"
type_identifier (4, 32) - (4, 35) "Int"
, (4, 35) - (4, 36) ","
class_parameter (4, 37) - (4, 58)
identifier (4, 37) - (4, 50) "locationInRun"
: (4, 50) - (4, 51) ":"
type_identifier (4, 52) - (4, 58) "String"
) (4, 58) - (4, 59) ")"
end (5, 2) - (5, 5) "end"
_end_ident (5, 6) - (5, 14) "Location"
end (7, 0) - (7, 3) "end"
_end_ident (7, 4) - (7, 9) "Merge"
Furthermore, moving the case class definition to the top level gives a correct parse even with the trailing colon:
package com.sageserpent.kineticmerge.core
case class Location(runIndex: Int, locationInRun: String):
end Location
compilation_unit (0, 0) - (4, 0)
package_clause (0, 0) - (0, 41)
package (0, 0) - (0, 7) "package"
package_identifier (0, 8) - (0, 41)
identifier (0, 8) - (0, 11) "com"
. (0, 11) - (0, 12) "."
identifier (0, 12) - (0, 23) "sageserpent"
. (0, 23) - (0, 24) "."
identifier (0, 24) - (0, 36) "kineticmerge"
. (0, 36) - (0, 37) "."
identifier (0, 37) - (0, 41) "core"
class_definition (2, 0) - (4, 0)
case (2, 0) - (2, 4) "case"
class (2, 5) - (2, 10) "class"
identifier (2, 11) - (2, 19) "Location"
class_parameters (2, 19) - (2, 57)
( (2, 19) - (2, 20) "("
class_parameter (2, 20) - (2, 33)
identifier (2, 20) - (2, 28) "runIndex"
: (2, 28) - (2, 29) ":"
type_identifier (2, 30) - (2, 33) "Int"
, (2, 33) - (2, 34) ","
class_parameter (2, 35) - (2, 56)
identifier (2, 35) - (2, 48) "locationInRun"
: (2, 48) - (2, 49) ":"
type_identifier (2, 50) - (2, 56) "String"
) (2, 56) - (2, 57) ")"
template_body (2, 57) - (4, 0)
: (2, 57) - (2, 58) ":"
end (3, 0) - (3, 3) "end"
_end_ident (3, 4) - (3, 12) "Location"
Given that there is a template body in this example, that should probably appear in the expected correct parse, so take the first expected output with a pinch of salt.
Where are you experiencing this error?
Difftastic, release 0.49 with a subtree merge of Treesitter at dd02e51
Vasil Markoukin commented
@sageserpent-open Thanks for reporting!