Issue 182 in j2objc: Switch case in protected scope

34 views
Skip to first unread message

j2o...@googlecode.com

unread,
May 24, 2013, 3:51:31 PM5/24/13
to j2objc-...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 182 by daniel....@gmail.com: Switch case in protected scope
http://code.google.com/p/j2objc/issues/detail?id=182

The translation of this method in Java:

private static int testMethod(int value) {

switch (value) {
case 1:
String test = "test";
return 2;
default:
return 4;
}
}
}

Produces this output:
+ (int)testMethodWithInt:(int)value {
switch (value) {
NSString *test;
case 1:
test = @"test";
return 2;
default:
return 4;
}
}

XCode complains (error) for both cases "1" and "default" - "Switch case is
in protected scope".
This happens when you define a String inside a case, it's not a problem
with an int (I am not experienced enough in Objective-C to answer why is
this a problem at all).

The fix is to move the declaration of test variable above the switch
statement.


--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

j2o...@googlecode.com

unread,
May 27, 2013, 8:50:34 AM5/27/13
to j2objc-...@googlegroups.com

Comment #1 on issue 182 by tobi.f...@gmail.com: Switch case in protected
scope
http://code.google.com/p/j2objc/issues/detail?id=182

duplicate of issue #172!

j2o...@googlecode.com

unread,
May 27, 2013, 8:52:14 AM5/27/13
to j2objc-...@googlegroups.com

Comment #2 on issue 182 by daniel....@gmail.com: Switch case in protected
scope
http://code.google.com/p/j2objc/issues/detail?id=182

Oops, I didn't notice that it already exists. But maybe this code example
is a bit more simple and easier to track down the problem.

j2o...@googlecode.com

unread,
Nov 21, 2013, 7:57:37 PM11/21/13
to j2objc-...@googlegroups.com
Updates:
Status: Fixed

Comment #3 on issue 182 by tb...@google.com: Switch case in protected scope
http://code.google.com/p/j2objc/issues/detail?id=182

The temporary variable is now moved outside of the switch statement, inside
a block to avoid clashing with other variables with that name:

{
NSString *test;
switch (value) {
case 1:
test = @"test";
return 2;
default:
return 4;
}
}


Reply all
Reply to author
Forward
0 new messages