-
Notifications
You must be signed in to change notification settings - Fork 46
T1002281 class cast ex #67
base: master
Are you sure you want to change the base?
Conversation
Fixes #1002281
Add public return types, add override keywords, remove trailing whitespace
Test PASSed. See Console Output in the link below for an update site containing this PR binary artefacts. Refer to this link for build results: https://jenkins.scala-ide.org:8496/jenkins/job/ghprb-scala-refactoring-validator/42/ |
def withPos(newPos: Position): Selection = { | ||
val p = newPos match { | ||
case p: RangePosition => p | ||
case p: OffsetPosition => new RangePosition(p.source, p.start, p.start, p.start) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, you really need a RangePosition
there. Why not throw as well on OffsetPosition
, rather than giving a RangePosition
which has high chances of being false ( I expect callers will want the word at point) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, and I wonder why we get an OffsetPosition in the first place...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess SI-8807 is one reason...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What could go wrong if OffsetPosition
is treated as RangePosition
? This way we need to ensure that no OffsetPosition
is passed into scala-refactoring otherwise it blows up. Maybe that is the right thing to do, then I just need to fix the ticket on the IDE side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There just shouldn't be a reason to use an OffsetPosition. Remember, they're only used for compiler generated trees, so if a refactoring is started from the editor, there should always be a better suited RangePosition available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, and having an exception on OffsetPositions works as a canary.
Test FAILed. |
Instead of doing an unsafe cast, an exception is thrown directly (or a conversion if possible).
Second commit contains cleanups.