Skip to content

Conversation

smowton
Copy link
Contributor

@smowton smowton commented Nov 3, 2022

This avoids extracting the default value expression in more than one place, which causes inconsistencies for e.g. anonymous classes, which expect to have a single new expression associated.

This avoids extracting the default value expression in more than one place, which causes inconsistencies for e.g. anonymous classes, which expect to have a single `new` expression associated.
@smowton smowton requested review from a team as code owners November 3, 2022 14:54
@github-actions github-actions bot added the Kotlin label Nov 3, 2022
Copy link
Contributor

@tamasvajk tamasvajk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What were the "inconsistencies for e.g. anonymous classes"?

@smowton
Copy link
Contributor Author

smowton commented Nov 4, 2022

@tamasvajk the isAnonymClass relation is supposed to be a bijection, meaning a one-to-one ClassInstanceExpr <-> AnonymousType relationship. If we extract the default value in both the $default function and a JvmOverloads function, then you end up with something like

fun f(x: SomeInterface = { a -> a }, y: Int)

becoming

fun f$default(var x: SomeInterface?, var y: Int?, argsMask: Int, ...) {
  if (!(argsMask & 1)) x = { a -> a }
  ...    
}

fun f(y: Int) {
  f({ a -> a }, y)
}

Thus the source-level class representing the anonymous class has been duplicated. We can handle that either by allowing that duplication and extracting two classes, or work around the problem by implementing fun f(y: Int) { f$default(null, y, 3, ...) }, which is the option I've taken here.

@tamasvajk
Copy link
Contributor

Thanks for the explanation, makes sense.

@smowton smowton merged commit 587aa93 into github:main Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants