Skip to content

Fix NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS compilation error #3826

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 2 commits into from
Aug 9, 2023
Merged
Changes from 1 commit
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
1 change: 1 addition & 0 deletions kotlinx-coroutines-core/jvm/test/TestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public actual typealias TestResult = Unit
* }
* ```
*/
@Suppress("NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS") // Counterpart for ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please elaborate on how we should proceed further with this suppress?

If this case is no longer supported (or was unsupported but not explicitly reported), shouldn't we have any kind of migration plan?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suppress is a counterpart for @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS"). You can see that you already have a @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") inside public actual open class TestBase.

If you didn't have @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") then NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS wouldn't be reported

Copy link
Member Author

@nikitabobko nikitabobko Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I had to rework the way we report ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS. Before my changes, it was a separate checker. Now it's checked in the expect-actual matcher and it's considered a common expect-actual mismatch incompatibility

And such types of expect-actual mismatch incompatibilities are reported two times:

// Common
expect class Bar {
    fun foo(): Any
}

// Platform
actual class Bar { // NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS (first time)
    actual fun foo(): String { // ACTUAL_WITHOUT_EXPECT (second time)
        return ""
    }
}

That's why you need to suppress ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS two times (But they are two separate diagnostics)

Copy link
Member Author

@nikitabobko nikitabobko Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably it will be more clear If I change Counterpart for ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS comment to Counterpart for @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full compilation error of NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS also makes it clear:

e: file:///home/bobko/jb/test-proj/kotlinx.coroutines/kotlinx-coroutines-core/jvm/test/TestBase.kt:57 Actual class 'TestBase' has no corresponding members for expected class members:

    public expect fun error(message: Any, cause: Throwable?): Nothing

    The following declaration is incompatible because actual function cannot have default argument values, they should be declared in the expected function:
        public actual fun error(message: Any, cause: Throwable? = null): Nothing

public actual open class TestBase(private var disableOutCheck: Boolean) {

actual constructor(): this(false)
Expand Down