Skip to content

GDScript: Disallow strings as comments - #121833

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
HolonProduction:rm-stupid
Aug 18, 2026
Merged

GDScript: Disallow strings as comments#121833
Repiteo merged 1 commit into
godotengine:masterfrom
HolonProduction:rm-stupid

Conversation

@HolonProduction

@HolonProduction HolonProduction commented Jul 27, 2026

Copy link
Copy Markdown
Member

What problem(s) does this PR solve?

Additional information

GDScript does allow string literals as multiline comments to some extends. E.g. they are excepted in a top level context, in contrast to other literals.

Note: This PR does not break compat. Using string literals at the top level is still accepted. What this PR does, is making string literals subject to "standalone expression" warnings.

This was introduced for 4.x with #72971. I think it made sense at the time, since it was in 3.x.

However it did surprise me that this was an (supposedly) intended thing, because:

image

All of this might be case for documentation. tl;dr However as outlined in #112523 the comment stripping that is offered by binary tokenization does not apply to string literals, so encouraging users to do this is a footgun. As such I think we should phase out this feature during 4.x.

In a scope context there is simply no good way to tell apart a user error and a "multi-line comment". And I'd rather warn users than keep an undocumented feature.

Note

I don't know how controversial this is. So if necessary I can open a proposal about it.

@Mickeon

Mickeon commented Jul 27, 2026

Copy link
Copy Markdown
Member

I would love this, but let me tell you right off the bat: this is most definitely going to be controversial and indeed it warrants a proposal, with the same sentiments brought up here.

If it were just up to me, I would still accept this and gather public feedback, personally.
Mainly to protect beginners. But also, by disabling the warning you acknowledge to be doing something unexpected or unconventional, which especially nowadays a "strings as comments" very much is.

"Nowadays", because using them may make even less sense with the general improvements made to the editor:

  • Toggling comments doesn't work the same as 4.0 and is overall regarded as more comfortable.
  • Words such as "TODO" are highlighted in comments
  • Documentation comments are highlighted more distinctly.
  • I was looking for Autofill comment when inserting a new line in documentation #95955 but I discovered that it wasn't merged at all. If it did, it would've made writing "multiline" comments more comfortable, and further justify removing this.

@HolonProduction

Copy link
Copy Markdown
Member Author

Alright I opened a proposal about it: godotengine/godot-proposals#15279

Putting in draft for the time being.

@HolonProduction
HolonProduction marked this pull request as draft July 28, 2026 10:48
@HolonProduction
HolonProduction force-pushed the rm-stupid branch 2 times, most recently from 896c3dd to 285a65c Compare August 11, 2026 07:50
@HolonProduction

Copy link
Copy Markdown
Member Author

I'm not seeing any pushback on the proposal, so I'd say this is ready for review.

@HolonProduction
HolonProduction marked this pull request as ready for review August 11, 2026 07:57
@Repiteo Repiteo modified the milestones: 4.x, 4.8 Aug 11, 2026

@Ivorforce Ivorforce left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I approve of the change - standalone strings have no use-case for us and we should lean in to comments for documentation. Implementation wise I think this is the perfect way to handle it: Backwards compat kept but adding warnings.

Code looks good to me.

Comment thread modules/gdscript/gdscript_parser.cpp Outdated
Comment thread modules/gdscript/gdscript_parser.h
@Repiteo
Repiteo merged commit 36130f8 into godotengine:master Aug 18, 2026
20 checks passed
@Repiteo

Repiteo commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Thanks!

@HolonProduction
HolonProduction deleted the rm-stupid branch August 18, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GDScript: Phase out string literals as multiline comments Dangling quoted lines does not generate a warning or error.

4 participants