D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 235 - goto & scope: cannot goto forward into different try block level
Summary: goto & scope: cannot goto forward into different try block level
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 All
: P2 normal
Assignee: Walter Bright
URL: http://www.digitalmars.com/drn-bin/ww...
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2006-07-02 10:49 UTC by Thomas Kühne
Modified: 2015-06-09 05:11 UTC (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Thomas Kühne 2006-07-02 10:49:09 UTC
According to DMD-0.162's documentation the code below is valid but is rejected by DMD: cannot goto forward into different try block level

void foo(bool b){
	if(b){
		goto label;
	}

	status = 2;
	scope(exit){
		status--;
	}

label:
	{
	}
}
Comment 2 Michael Arntzenius 2006-11-20 16:51:07 UTC
I've verified this bug on DMD 0.174. In addition, the same problem appears in the following code:

class Foo {
    invariant {}
    synchronized void foo() { return; }
}

After fiddling around to see when an error occurs, it seems the problem arises in the presence of the combination of both an invariant and a synchronized method with a return statement (even if the invariant and return statement do nothing, as in the example above). However, I've managed to get code which has this combination to compile on Windows under DMD 0.174, but the same code would not compile on Linux, as it caused this error, so it may be a linux-only problem.

Since having invariants and synchronized methods in the same class is far from an uncommon use-case, I'm raising the severity of this bug to critical.
Comment 3 Michael Arntzenius 2006-11-20 17:33:56 UTC
The same error appears when using "out" contracts on synchronized methods with return statements in them, for example:

class Foo {    
    synchronized void foo()
    out {} body { return; }
}
Comment 4 Thomas Kühne 2006-11-22 07:50:23 UTC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

d-bugmail@puremagic.com schrieb am 2006-11-20:
> http://d.puremagic.com/issues/show_bug.cgi?id=235

> ------- Comment #2 from daekharel@gmail.com  2006-11-20 16:51 -------
> I've verified this bug on DMD 0.174. In addition, the same problem appears in
> the following code:
>
> class Foo {
>     invariant {}
>     synchronized void foo() { return; }
> }
>
> After fiddling around to see when an error occurs, it seems the problem arises
> in the presence of the combination of both an invariant and a synchronized
> method with a return statement (even if the invariant and return statement do
> nothing, as in the example above). However, I've managed to get code which has
> this combination to compile on Windows under DMD 0.174, but the same code would
> not compile on Linux, as it caused this error, so it may be a linux-only
> problem.
>
> Since having invariants and synchronized methods in the same class is far from
> an uncommon use-case, I'm raising the severity of this bug to critical.

Added to DStress as
http://dstress.kuehne.cn/run/s/scope_14_C.d
http://dstress.kuehne.cn/run/s/scope_14_D.d
http://dstress.kuehne.cn/run/s/scope_14_E.d
http://dstress.kuehne.cn/run/s/scope_14_F.d

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFFZEoJLK5blCcjpWoRApdcAJ9c365wajdUZGYLJQkDdIksT8GIJgCfQSMo
qKv6uGZ8JfQx5DCCd8V7mrw=
=Qqur
-----END PGP SIGNATURE-----

Comment 5 torhu 2008-01-24 16:34:27 UTC
I don't know if it matters, but when compiling with -o-, I don't get this error message.  I tried the DStress 14_C test case with 1.023 on linux.

I had to prefix a class invariant with 'version (Windows)' to fix this in some code of my own.
Comment 6 Mario Kroeplin 2009-07-18 06:10:06 UTC
Some contracts on 'synchronized' functions are still rejected by the compilers D_1.046 and D_2.031 without indicating line numbers or providing intelligible information.
Comment 7 Brad Roberts 2009-07-18 10:32:20 UTC
Mario, are you reporting that this bug isn't fixed, or that you have other test cases that include additional issues?  If you have additional test cases that produce different issues please file a new bug and include complete examples including both the code to reproduce it and the output from the compiler that shows exactly what you're showing to be done wrong.  Vague reports like your reply here aren't particularly actionable.
Comment 8 puremagic.com 2009-09-16 01:37:26 UTC
Concerning Michael Arntzenius comment: After running into this problem in linux (DMD 1.043), I can confirm that exactly his example compiles on _neither_ linux (DMD 1.043) or OSX (DMD 1.046)...  so it's apparently not quite linux-only (although I suppose the linux and OSX source code is substantially the same...).

"Error: cannot goto forward into different try block level".

In both cases, -o- makes the error message go away as suggested by torhu@yahoo.com, but this doesn't seem like a terribly useful observation (at least not from the perspective of a user ,-))
Comment 9 Don 2010-11-24 19:40:57 UTC
Starting with 1.064, the error message has changed to "cannot goto into try block". The code compiles on 2.010 and later.
Comment 10 Andrei Alexandrescu 2010-11-26 10:35:59 UTC
Downgrading severity as there are plenty of workarounds.
Comment 11 Andrei Alexandrescu 2013-11-15 19:24:22 UTC
Just tried it now, works as expected.