[1.2-M1] - New array literal syntax compiler error

Hi,

I tried the new array literal syntax and the compiler crashed.
What I did was declared the following class

import com.vaadin.annotations.JavaScript
import com.vaadin.ui.AbstractJavaScriptComponent


@JavaScript(*[
"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js",
"http://caldwell.github.io/renderjson/renderjson.js",
"jsonview.js",
"jsonview-connector.js"]
)
class JsonView : AbstractJavaScriptComponent()

And this generated to following compiler error:

λ gradle testClasses
e: org.jetbrains.kotlin.util.KotlinFrontEndException: Exception while analyzing expression at (7,14) in C:/work/cartrawler/git/shopdirect/src/main/kotlin/com/cartrawler/shopdirect/ui/JsonView.kt:
[
https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js”,
http://caldwell.github.io/renderjson/renderjson.js”,
“jsonview.js”,
“jsonview-connector.js”]

    at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.logOrThrowException(ExpressionTypingVisitorDispatcher.java:250)
    at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:221)
    at org.jetbrains.kotlin.util.PerformanceCounter.time(PerformanceCounter.kt:90)
    at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:171)
    at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:142)
    at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:121)
    at org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver.getArgumentTypeInfo(ArgumentTypeResolver.java:225)
    at org.jetbrains.kotlin.resolve.calls.CandidateResolver.checkValueArgumentTypes(CandidateResolver.kt:366)
    at org.jetbrains.kotlin.resolve.calls.CandidateResolver.checkAllValueArguments(CandidateResolver.kt:344)
    at org.jetbrains.kotlin.resolve.calls.CandidateResolver.checkValueArguments(CandidateResolver.kt:110)
    at org.jetbrains.kotlin.resolve.calls.CandidateResolver.performResolutionForCandidateCall(CandidateResolver.kt:96)
    at org.jetbrains.kotlin.resolve.calls.tower.NewResolutionOldInference.runResolutionForGivenCandidates(NewResolutionOldInference.kt:213)
    at org.jetbrains.kotlin.resolve.calls.CallResolver.doResolveCall(CallResolver.java:623)
    at org.jetbrains.kotlin.resolve.calls.CallResolver.doResolveCallOrGetCachedResults(CallResolver.java:529)

This issue is fixed in Kotlin 1.2-M2, which wiil be released soonish.

1 Like

Hi @yole:

Amazing, To be honest what would really be nice is if did not had to put the ‘*’ for the array literal declaration.

Kindly
Luis Oscar

@JavaScript(*[...]) – star is the spread operator here. You’re creating an array and passing it with the spread operator where vararg parameters are expected. Instead you can just pass those strings as varargs:

@JavaScript(
"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js",
"http://caldwell.github.io/renderjson/renderjson.js",
"jsonview.js",
"jsonview-connector.js"
)

ops, :slight_smile: thank you learned something new today.