Skip to content

Add code fix for double literal without dot#3352

Open
amcasey wants to merge 7 commits into
mainfrom
amcasey/i2d
Open

Add code fix for double literal without dot#3352
amcasey wants to merge 7 commits into
mainfrom
amcasey/i2d

Conversation

@amcasey

@amcasey amcasey commented Jun 17, 2026

Copy link
Copy Markdown
Member

It's very easy to write 2 when you mean 2.. Offer a code fix.

@amcasey

amcasey commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

I don't really care whether we merge this. I make this mistake pretty regularly in Q#, but I mostly implemented it to practice writing rust without copilot.

With all the time in the world, I'd probably experiment with having type inference infer either Int or Double for integer literals, depending on the context. In such a world, we might want a suffix to force the literal to Int, but the only place I can think of where both are allowed and the difference matters is division.

operation Foo(qs: Qubit[]) : Unit is Adj {
use q = Qubit();
Foo(q);
Foo(◉◉q◉◉);

@amcasey amcasey Jun 17, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we switched from one edit to two, the updated test became less meaningful as confirmation that the action was behaving correctly, so now we check the locations of the edits too.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Q# language service code action that offers a quick fix when an integer literal is used where a Double is expected, by inserting a trailing . (e.g., 22.). This fits into the existing source/language_service/src/code_action/ quick-fix providers alongside existing fixes like “wrap in array”.

Changes:

  • Add int_to_double code action provider and wire it into get_code_actions.
  • Add a new test suite for the int-to-double quick fix (including unary +/-, parens cases).
  • Strengthen existing “wrap in array” tests by asserting edit ranges against marker-derived expected locations.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
source/language_service/src/code_action/wrap_in_array/tests.rs Updates tests to use marker-derived Locations and assert edit ranges precisely.
source/language_service/src/code_action/int_to_double/tests.rs New tests validating the “Convert to double literal” code action behavior across several expression shapes.
source/language_service/src/code_action/int_to_double.rs New quick-fix implementation that inserts a trailing . for Int literal mismatches against expected Double.
source/language_service/src/code_action.rs Registers the new int_to_double provider in the code actions pipeline.

Comment thread source/language_service/src/code_action/int_to_double.rs Outdated
Comment thread source/language_service/src/code_action/int_to_double.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants