mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
472 stars 131 forks source link

Wrong IncorrectNumberOfArgumentsInExpression in match-expression #2283

Open Copatych opened 8 months ago

Copatych commented 8 months ago

Environment

Observed behavior and steps to reproduce

I get lint error IncorrectNumberOfArgumentsInExpression "Incorrect number of expressions within match Expression: expected an even number, but 5 was found." in this code:

enum class Type(@ColorInt val color: Int) {
    RED(Color.RED),
    GREEN(Color.GREEN),
    BLUE(Color.BLUE);
}

fun Expression.ExpressionBuilder.getColor(type: Type) {
    stop {
        literal(type.name)
        color(type.color)
    }
}
...
// there is IncorrectNumberOfArgumentsInExpression
lineColor(
    match {
        get("type")
        getColor(Type.RED)
        getColor(Type.GREEN)
        getColor(Type.BLUE)
        color(Color.BLACK)
    }
)

This code does not have an error:

lineColor(
    match {
        get("type")
        stop {
            literal(Type.RED.name)
            color(Type.RED.color)
        }
        stop {
            literal(Type.GREEN.name)
            color(Type.GREEN.color)
        }
        stop {
            literal(Type.BLUE.name)
            color(Type.BLUE.color)
        }
        color(Color.BLACK)
    }
)

Expected behavior

No lint error IncorrectNumberOfArgumentsInExpression

Notes / preliminary analysis

Additional links and references

example code https://github.com/Copatych/MapboxBugs/blob/IncorrectNumberOfArgumentsInExpression_bug/app/src/main/java/com/example/mapboxbugs/MainActivity.kt

Krzysztof-Daniluk commented 7 months ago

Same here

iolandarosavoid commented 5 months ago

I see the same warning in my code related with stop expressions, match expressions.... But anything is wrong.

I am currently using Mapbox version 11.3.0.

enurez30 commented 1 month ago

I'm using Mapbox version 11.6.0 and facing the same warning related stop and match expressions.