Bug 235 – goto & scope: cannot goto forward into different try block level

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2006-07-02T10:49:00Z
Last change time
2015-06-09T05:11:47Z
Keywords
rejects-valid
Assigned to
bugzilla
Creator
thomas-dloop

Comments

Comment #0 by thomas-dloop — 2006-07-02T10:49:09Z
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 #1 by thomas-dloop — 2006-07-02T10:53:20Z
Comment #2 by daekharel — 2006-11-20T16:51:07Z
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 by daekharel — 2006-11-20T17:33:56Z
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 by thomas-dloop — 2006-11-22T07:50:23Z
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [email protected] schrieb am 2006-11-20: > http://d.puremagic.com/issues/show_bug.cgi?id=235 > ------- Comment #2 from [email protected] 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 by torhu — 2008-01-24T16:34:27Z
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 by kroeplin.d — 2009-07-18T06:10:06Z
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 by braddr — 2009-07-18T10:32:20Z
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 by puremagic.com — 2009-09-16T01:37:26Z
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 [email protected], but this doesn't seem like a terribly useful observation (at least not from the perspective of a user ,-))
Comment #9 by clugdbug — 2010-11-24T19:40:57Z
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 by andrei — 2010-11-26T10:35:59Z
Downgrading severity as there are plenty of workarounds.
Comment #11 by andrei — 2013-11-15T19:24:22Z
Just tried it now, works as expected.