Skip to content

Can't access public static fields inherited from a protected static interface from scala code #9272

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

Open
scabug opened this issue Apr 15, 2015 · 9 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Apr 15, 2015

this code, for a very ugly API:

val ops: java.util.ArrayList[ContentProviderOperation] = new java.util.ArrayList[ContentProviderOperation]
    ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
            .withValue(RawContacts.ACCOUNT_TYPE, AccountType)
            .withValue(RawContacts.ACCOUNT_NAME, AccountName).build)

doesn't compile

[error] <snip>.scala:63: value ACCOUNT_TYPE is not a member of object android.provider.ContactsContract.RawContacts
[error]             .withValue(RawContacts.ACCOUNT_TYPE, AccountType)
[error]                                    ^
[error] <snip>.scala:64: value ACCOUNT_NAME is not a member of object android.provider.ContactsContract.RawContacts
[error]             .withValue(RawContacts.ACCOUNT_NAME, AccountName).build)

RawContacts is a public static class which implements the SyncColumns protected static interface (among others), both defined in android.provider.ContactsContract.
RawContacts inherits those public static fields from SyncColumns, but scalac just doesn't see them.

The scaloid guy wrote a workaround but it's only a hardcoded bridge for this specific API. Note that he refers to #1086 but that seems like a different bug.

@scabug
Copy link
Author

scabug commented Apr 15, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9272?orig=1
Reporter: Mikel Pérez (mikelpr)
Affected Versions: 2.11.6
See #1086

@scabug
Copy link
Author

scabug commented Apr 15, 2015

@soc said:
So RawContacts can't be used because the member is (correctly) not there (static members don't participate in inheritance) and SyncColumns can't be used because it is protected?

It seems like it's not exactly the same symptom as in #1086, but the same root cause.

@scabug
Copy link
Author

scabug commented Apr 15, 2015

Mikel Pérez (mikelpr) said:
yep exactly that

@hrhino
Copy link

hrhino commented Oct 11, 2017

A reproduction that doesn't require Android:

hhoughton:tmp hhoughton$ cat Ax.java Sax.java Wax.java
// Ax.java
package a;

public class Ax {
  protected static interface Max {
    static int Bax = 1;
  }
}

// Sax.java
package a;

public class Sax implements Ax.Max {}


// Wax.java
package b;

import a.*;

public class Wax {
  int hax = Sax.Bax;
}


hhoughton:tmp hhoughton$ javac Ax.java Sax.java Wax.java
hhoughton:tmp hhoughton$ scala-launch 2.12.4-bin-c2a5883 -cp .
Welcome to Scala 2.12.4-bin-c2a5883 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_121).
Type in expressions for evaluation. Or try :help.

scala> val flax = Sax.Bax
<console>:11: error: value Bax is not a member of object Sax
       val flax = Sax.Bax
                      ^

@hrhino hrhino closed this as completed Jan 12, 2018
@SethTisue
Copy link
Member

@hrhino why closed?

@hrhino
Copy link

hrhino commented Jan 16, 2018

Ach sorry. I thought this was the one I closed in scala/scala#6058 (was double checking regarding the regression tickets surrounding that, since the github "auto-close" didn't work).

@SethTisue
Copy link
Member

SethTisue commented Oct 30, 2018

I would be comfortable simply closing this as "not a bug", working as designed. Scala doesn't have statics. We must interoperate with them to whatever extent that is actually needed, but I don't think we need to imitate everything about how javac handles them. (see @lrytz's comment at #11226 (comment))

@lrytz
Copy link
Member

lrytz commented Nov 1, 2018

The issue is there's no way to acess Bax (in #9272 (comment)) in Scala, but it's possible in Java, so some Java API might be not usable in Scala. You'd have to write an accessor in Java. Maybe that's ok?

@SethTisue SethTisue added this to the Backlog milestone Nov 1, 2018
@SethTisue
Copy link
Member

Ah, I hadn't understood that, thanks for clarifying.

I'll modify my statement, then: doing anything at all about this seems low priority to me, but of course we'd consider a pull request if someone has a design and implementation in mind.

unlsycn added a commit to unlsycn/zaozi that referenced this issue Feb 12, 2025
Jextract splits the header class into multiple classes, which are combined via
extending. Due to scala/bug#9272 we cannot access
static fields in superclass headers, we work around this by not splitting the
header.

Signed-off-by: unlsycn <unlsycn@unlsycn.com>
unlsycn added a commit to unlsycn/zaozi that referenced this issue Feb 12, 2025
Jextract splits the header class into multiple classes, which are combined via
extending. Due to scala/bug#9272 we cannot access
static fields in superclass headers, we work around this by not splitting the
header.

Signed-off-by: unlsycn <unlsycn@unlsycn.com>
unlsycn added a commit to unlsycn/zaozi that referenced this issue Feb 12, 2025
Jextract splits the header class into multiple classes, which are combined via
extending. Due to scala/bug#9272 we cannot access
static fields in superclass headers, we work around this by not splitting the
header.

Signed-off-by: unlsycn <unlsycn@unlsycn.com>
unlsycn added a commit to unlsycn/zaozi that referenced this issue Feb 12, 2025
Jextract splits the header class into multiple classes, which are combined via
extending. Due to scala/bug#9272 we cannot access
static fields in superclass headers, we work around this by not splitting the
header.

Signed-off-by: unlsycn <unlsycn@unlsycn.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants