Skip to content

Commit

Permalink
Fix potential issue with overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
sschr15 committed Dec 18, 2024
1 parent 0d03cf4 commit 238db71
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ allprojects {

name = "AoC Utility Kotlin Compiler Plugin"
description = "Adds some utilities to code, developed originally for Advent of Code solving"
url = "https://github.com/advent-of-code/"
url = "https://github.com/sschr15/advent-of-code/"

developers {
developer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sschr15.aoc.annotations
package com.sschr15.aoc.annotations

/**
* Marks an expression to skip overflow and underflow checks.
Expand Down
11 changes: 9 additions & 2 deletions compiler-plugin/src/main/kotlin/OverflowUnderflowChecker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class OverflowUnderflowChecker(private val context: IrPluginContext, private val
"rem",
)

val singleArgumentTypeChecks = setOf(
"inc", "dec", "unaryMinus", "abs",
)

val intConversions = setOf("toFloat")
val longConversions = setOf("toInt", "toDouble", "toFloat")
val absoluteValueName = Name.special("<get-absoluteValue>")
Expand Down Expand Up @@ -112,8 +116,11 @@ class OverflowUnderflowChecker(private val context: IrPluginContext, private val
val primitiveType = expression.type.getPrimitiveType() ?: return super.visitCall(expression)
if (primitiveType != PrimitiveType.INT && primitiveType != PrimitiveType.LONG) return super.visitCall(expression)
if (expression.symbol.owner.name.asString() !in singleTypeChecks) return super.visitCall(expression)
if (expression.valueArgumentsCount == 2 && expression.getValueArgument(0)!!.type != expression.getValueArgument(1)!!.type) {
config.report(CompilerMessageSeverity.WARNING, "Arguments to arithmetic operations are of different types, skipping overflow check")
if (
(expression.valueArgumentsCount != 2 || expression.getValueArgument(0)!!.type != expression.getValueArgument(1)!!.type) &&
(expression.valueArgumentsCount != 1 || !singleArgumentTypeChecks.contains(expression.symbol.owner.name.asString()))
) {
config.report(CompilerMessageSeverity.WARNING, "Unexpected number of arguments for ${expression.symbol.owner.name}, skipping")
return super.visitCall(expression)
}

Expand Down

0 comments on commit 238db71

Please sign in to comment.