mapbox / mapbox/mapbox-maps-android

Wrong IncorrectNumberOfArgumentsInExpression in match-expression

Open
#2,283 4 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle:
Dominant language
Kotlin
Stars
578
Forks
161
PR merge metrics
No merged PRs in 30d

Description

Environment

  • Android OS version: No matter
  • Devices affected: No matter
  • Maps SDK Version: 11.1.0

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction in MainActivity.kt from the linked example, using Maps SDK 11.1.0, and run the lint checks that report IncorrectNumberOfArgumentsInExpression. Compare the helper-based match expression with the inline stop expressions; done means the reported lint error is no longer produced for the shown code.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.