Skip to content

Correct accessibily for package-private fields #1685

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

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ import org.utbot.framework.plugin.api.util.doubleStreamClassId
import org.utbot.framework.plugin.api.util.doubleStreamToArrayMethodId
import org.utbot.framework.plugin.api.util.intStreamClassId
import org.utbot.framework.plugin.api.util.intStreamToArrayMethodId
import org.utbot.framework.plugin.api.util.isPackagePrivate
import org.utbot.framework.plugin.api.util.isSubtypeOf
import org.utbot.framework.plugin.api.util.longStreamClassId
import org.utbot.framework.plugin.api.util.longStreamToArrayMethodId
Expand Down Expand Up @@ -1112,7 +1113,11 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
private fun FieldId.getAccessExpression(variable: CgVariable): CgExpression =
// Can directly access field only if it is declared in variable class (or in its ancestors)
// and is accessible from current package
if (variable.type.hasField(this) && canBeReadFrom(context)) {
if (variable.type.hasField(this)
//TODO: think about moving variable type checks into [isAccessibleFrom] after contest
&& (!isPackagePrivate || variable.type.packageName == context.testClassPackageName)
&& canBeReadFrom(context)
) {
if (jField.isStatic) CgStaticFieldAccess(this) else CgFieldAccess(variable, this)
} else {
utilsClassId[getFieldValue](variable, this.declaringClass.name, this.name)
Expand Down