Skip to content

Commit bea6371

Browse files
committed
Annotate static fields with accessibility
This mirrors the annotation already present on methods, and is needed to resolve indirect reference to an inherited static field, similar to virtual call resolution. The access attribute is set as a comment so that in an assignment some_static_field = some_constant we don't need to attach spurious access tags to the constant, or scrub them from the field, for their types to be considered matching.
1 parent 168c2a8 commit bea6371

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/java_bytecode/java_bytecode_convert_class.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,20 @@ void java_bytecode_convert_classt::convert(
391391
"."+id2string(f.name);
392392
new_symbol.mode=ID_java;
393393
new_symbol.is_type=false;
394+
395+
// These annotations use `ID_C_access` instead of `ID_access` like methods
396+
// to avoid type clashes in expressions like `some_static_field = 0`, where
397+
// with ID_access the constant '0' would need to have an access modifier
398+
// too, or else appear to have incompatible type.
399+
if(f.is_public)
400+
new_symbol.type.set(ID_C_access, ID_public);
401+
else if(f.is_protected)
402+
new_symbol.type.set(ID_C_access, ID_protected);
403+
else if(f.is_private)
404+
new_symbol.type.set(ID_C_access, ID_private);
405+
else
406+
new_symbol.type.set(ID_C_access, ID_default);
407+
394408
const namespacet ns(symbol_table);
395409
new_symbol.value=
396410
zero_initializer(

0 commit comments

Comments
 (0)