Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asserts are no longer enabled by default for non-debug sessions #4379

Closed
bwilkerson opened this issue Feb 8, 2023 · 3 comments
Closed

Asserts are no longer enabled by default for non-debug sessions #4379

bwilkerson opened this issue Feb 8, 2023 · 3 comments
Labels
in debugger Relates to the debug adapter or process of launching a debug session is bug
Milestone

Comments

@bwilkerson
Copy link

There might already be a way to do this that I didn't find, but I would like to be able to run code with asserts enabled without having to be running under the debugger. The primary motivation for not using the debugger is that the code runs slower.

My guess is that this would need to be a preference setting, but I'm happy with any solution you think would be best.

@DanTup
Copy link
Member

DanTup commented Feb 8, 2023

Hmmm, on the surface this feels like a bug to me. I was under the impression we always ran with asserts enabled from the IDE by default (because I assumed at dev time that's what you'd want), however I can repro this doesn't work and it's because of this isDebug here:

if (isDebug && debugConfig.enableAsserts !== false) // undefined = on
this.addArgsIfNotExist(args, "--enable-asserts");

It was added during the migration of flags from inside the debug adapter into the VS Code extension (to simplify the new debug adapters), but it doesn't appear to have had this condition when it was in the debug adapter. The change doesn't describe that it was deliberate, although it seems hard to do this accidentally.

I'm going to try removing that condition and running the bots and see what happens.

In the meantime, if you have a launch.json you can add --enable-asserts to toolArgs. This will apply to running using the Run/Debug menu (and pressing F5 etc.), but to make it apply to the Run/Debug CodeLens (the links above main/test/group methods), it needs to be marked as a template with templateFor: "":

{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "dart",
			"request": "launch",
			"type": "dart",
			"toolArgs": [
				"--enable-asserts" // enable asserts
			],
			"templateFor": "", // use as the template for Run/Debug for the whole project (this is a path prefix, empty string matches the entire project)
		}
	]
}

@DanTup
Copy link
Member

DanTup commented Feb 8, 2023

This was originally implemented in af06b7f for #3702 but had no tests which would've probably have picked up the regression.

Bots are all green so I'm going to restore this (and add tests).

@DanTup DanTup changed the title A way to enable asserts when not running the debugger Asserts are no longer enabled by default for non-debug sessions Feb 8, 2023
@DanTup DanTup added is bug in debugger Relates to the debug adapter or process of launching a debug session and removed is enhancement labels Feb 8, 2023
@DanTup DanTup added this to the v3.60.0 milestone Feb 8, 2023
@DanTup DanTup closed this as completed in c0e0203 Feb 8, 2023
DanTup added a commit that referenced this issue Feb 8, 2023
@DanTup
Copy link
Member

DanTup commented Feb 8, 2023

@bwilkerson btw I kicked off a pre-release version with this in it earlier. If you're on the pre-release Dart extension and have updated to v3.59.20230208 (note the last digit is an 8, there was a pre-release yesterday ending 7 but otherwise the same) and reloaded, then asserts should be on by default and not need the launch.json gymnastics above (unless you want to disable asserts).

I can't be certain this change in default behaviour won't upset anyone, but it was the original and intended behaviour. If this poses a problem we can add a setting to make it easier to control without needing a launch configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in debugger Relates to the debug adapter or process of launching a debug session is bug
Projects
None yet
Development

No branches or pull requests

2 participants