After updating Kotlin from 1.3.10 to 1.3.50 for a ...
# kotlin-native
n
After updating Kotlin from 1.3.10 to 1.3.50 for a Kotlin Native project, and running the project as a program a strange error appears:
Copy code
type Nothing? is not supported here: doesn't correspond to any C type
Double checked the mapping (in the knm file) and found that the return type is
CPointer<gtk3.GtkWidget>?
for the function (
gtk_file_chooser_dialog_new
) that is called in the program. However the function definition looks very odd:
Copy code
@kotlinx.cinterop.internal.CCall public external fun gtk_file_chooser_dialog_new(@kotlinx.cinterop.internal.CCall.CString title: kotlin.String?, parent: kotlinx.cinterop.CValuesRef<gtk3.GtkWindow /* = gtk3._GtkWindow */>?, action: gtk3.GtkFileChooserAction, @kotlinx.cinterop.internal.CCall.CString first_button_text: kotlin.String?, vararg variadicArguments: kotlin.Any?): kotlinx.cinterop.CPointer<gtk3.GtkWidget /* = gtk3._GtkWidget */>? { /* compiled code */ }
Below is the piece of code that contains the function call:
Copy code
private fun createOpenDialog(parent: CPointer<GtkWindow>?) = gtk_file_chooser_dialog_new(
        parent = parent,
        title = "Open File",
        first_button_text = "gtk-cancel",
        action = GtkFileChooserAction.GTK_FILE_CHOOSER_ACTION_OPEN,
        variadicArguments = *arrayOf(GTK_RESPONSE_CANCEL, "gtk-open", GTK_RESPONSE_ACCEPT, null)
    )
m
AFAIK vararg functions are now unsupported by
cinterop
n
What is the migration path from vararg functions?
o
in your case its trivial, just explicitly pass
GTK_RESPONSE_CANCEL, "gtk-open", GTK_RESPONSE_ACCEPT, null
as arguments
n
This is the new definition where positional parameters are now being used (in the
gtk_file_chooser_dialog_new
function):
Copy code
private fun createOpenDialog(parent: CPointer<GtkWindow>?) = gtk_file_chooser_dialog_new(
        "Open File",
        parent,
        GtkFileChooserAction.GTK_FILE_CHOOSER_ACTION_OPEN,
        "gtk-cancel",
        GTK_RESPONSE_CANCEL,
        "gtk-open",
        GTK_RESPONSE_ACCEPT,
        null
    )
Is this the correct way to do it? Ran the project as a program again and the same error message appears:
Copy code
e: /home/napperley/idea_projects/kpad/src/linuxMain/kotlin/org/example/kpad/Controller.kt: (103, 9): type Nothing? is not supported here: doesn't correspond to any C type
Appears as though the compiler is objecting to
null
being passed through as a parameter to the C function (
gtk_file_chooser_dialog_new
), very strange.
s
Please use properly-typed
null
, e.g.
null as COpaquePointer?
.