Skip to content

Conversation

@jpobst
Copy link
Contributor

@jpobst jpobst commented Dec 10, 2019

Context: #534

There are cases where Kotlin generates Java methods that are not allowed Java identifier names:

abstract class Bar {
    abstract void foo-WZ4Q5Ns(int);
}

interface IBar {
    void foo-WZ4Q5Ns(int);
}

In this case we cannot allow the user to implement the class as the mangled method cannot be implemented. We still need the class to be bound because there might be a Kotlin-created subclass
that needs the base class to exist.

There's no foolproof way to mark these as "not implementable". The best we can do for now is to detect if the user implements them in GenerateJavaStubs and give an informative error at that point.

This PR adds this error:

 error XA4213: Cannot override Kotlin-generated method 'foo-WZ4Q5Ns' because it 
 is not a valid Java method name. This method can only be overridden from Kotlin.

@jpobst jpobst force-pushed the javastubs-kotlin-error branch from 59a944a to 7df96af Compare December 10, 2019 16:38
@jpobst jpobst requested a review from jonpryor December 11, 2019 16:21
@jpobst jpobst force-pushed the javastubs-kotlin-error branch from 7df96af to 20417e5 Compare December 11, 2019 21:14
@jonpryor jonpryor merged commit f3553f4 into master Dec 12, 2019
@jonpryor jonpryor deleted the javastubs-kotlin-error branch December 12, 2019 02:13
jonpryor pushed a commit that referenced this pull request Dec 12, 2019
…537)

Context: #534
Context: #535
Context: 0065de4

There are cases where Kotlin generates Java methods that are not
valid Java identifiers:

	// `javap` output for a Kotlin type using UInt parameters
	public abstract class Bar {
	    abstract void foo-WZ4Q5Ns(int);
	}

	public interface IBar {
	    void foo-WZ4Q5Ns(int);
	}

In this case we cannot allow the user to inherit from the class or
implement the interface as the mangled method cannot be present
within Java Callable Wrapper source code.

We still need the class to be bound because there might be a Kotlin-
created subclass that needs the base class to exist.

There's no foolproof way to mark these as "not implementable".  The
best we can do for now is to detect if the user implements them in
the `<GenerateJavaStubs/>` task / `JavaCallableWrapperGenerator` and
give an informative error at that point.

Update `JavaCallableWrapperGenerator` so that when a Kotlin-generated
mangled method name is encountered, an XA4213 error is emitted:

	error XA4213: Cannot override Kotlin-generated method 'foo-WZ4Q5Ns'
	because it is not a valid Java method name.
	This method can only be overridden from Kotlin.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants