Skip to content

Commit

Permalink
SLC: use proper source PSI for no-arg constructor
Browse files Browse the repository at this point in the history
If no-arg constructor stems from the primary constructor
(e.g., when all arguments have a default value), that primary
constructor should be used as source PSI.
Otherwise, i.e., literally default constructor, the containing class is
the source PSI.

^KT-70491 fixed
  • Loading branch information
jsjeon authored and teamcity committed Aug 12, 2024
1 parent 4e8d0d0 commit 1e2f74a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ internal fun SymbolLightClassBase.createConstructors(
val primaryConstructor = constructors.singleOrNull { it.isPrimary }
if (primaryConstructor != null && shouldGenerateNoArgOverload(primaryConstructor, constructors)) {
result.add(
noArgConstructor(primaryConstructor.compilerVisibility.externalDisplayName, METHOD_INDEX_FOR_NO_ARG_OVERLOAD_CTOR)
noArgConstructor(
primaryConstructor.compilerVisibility.externalDisplayName,
primaryConstructor.sourcePsiSafe(),
METHOD_INDEX_FOR_NO_ARG_OVERLOAD_CTOR
)
)
}
}
Expand Down Expand Up @@ -198,14 +202,15 @@ private fun SymbolLightClassBase.defaultConstructor(): KtLightMethod {
else -> PsiModifier.PUBLIC
}

return noArgConstructor(visibility, METHOD_INDEX_FOR_DEFAULT_CTOR)
return noArgConstructor(visibility, classOrObject, METHOD_INDEX_FOR_DEFAULT_CTOR)
}

private fun SymbolLightClassBase.noArgConstructor(
visibility: String,
declaration: KtDeclaration?,
methodIndex: Int,
): KtLightMethod = SymbolLightNoArgConstructor(
kotlinOrigin?.let {
declaration?.let {
LightMemberOriginForDeclaration(
originalElement = it,
originKind = JvmDeclarationOriginKind.OTHER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum Em {
/**
* public final class Foo : kotlin/Any {
*
* // signature: <init>(ZBCCSIJFDLjava/lang/String;[I[J[D[Ljava/lang/String;Ljava/lang/Class;[Ljava/lang/Class;LEm;[LEm;)V
* // signature: <init>(ZBCCSIJFDLjava/lang/String;[I[J[DLkotlin/Array;Ljava/lang/Class;Lkotlin/Array;LEm;Lkotlin/Array;)V
* public constructor(z: kotlin/Boolean (* = ... *), b: kotlin/Byte (* = ... *), c: kotlin/Char (* = ... *), c2: kotlin/Char (* = ... *), sh: kotlin/Short (* = ... *), i: kotlin/Int (* = ... *), l: kotlin/Long (* = ... *), f: kotlin/Float (* = ... *), d: kotlin/Double (* = ... *), s: kotlin/String (* = ... *), iarr: kotlin/IntArray (* = ... *), larr: kotlin/LongArray (* = ... *), darr: kotlin/DoubleArray (* = ... *), sarr: kotlin/Array<kotlin/String> (* = ... *), cl: java/lang/Class<*> (* = ... *), clarr: kotlin/Array<java/lang/Class<*>> (* = ... *), em: Em (* = ... *), emarr: kotlin/Array<Em> (* = ... *))
*
* // signature: foo(I)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum Em {
/**
* public final class Foo : kotlin/Any {
*
* // signature: <init>(ZBCCSIJFDLjava/lang/String;[I[J[D[Ljava/lang/String;Ljava/lang/Class;[Ljava/lang/Class;LEm;[LEm;)V
* // signature: <init>(ZBCCSIJFDLjava/lang/String;[I[J[DLkotlin/Array;Ljava/lang/Class;Lkotlin/Array;LEm;Lkotlin/Array;)V
* public constructor(z: kotlin/Boolean (* = ... *), b: kotlin/Byte (* = ... *), c: kotlin/Char (* = ... *), c2: kotlin/Char (* = ... *), sh: kotlin/Short (* = ... *), i: kotlin/Int (* = ... *), l: kotlin/Long (* = ... *), f: kotlin/Float (* = ... *), d: kotlin/Double (* = ... *), s: kotlin/String (* = ... *), iarr: kotlin/IntArray (* = ... *), larr: kotlin/LongArray (* = ... *), darr: kotlin/DoubleArray (* = ... *), sarr: kotlin/Array<kotlin/String> (* = ... *), cl: java/lang/Class<*> (* = ... *), clarr: kotlin/Array<java/lang/Class<*>> (* = ... *), em: Em (* = ... *), emarr: kotlin/Array<Em> (* = ... *))
*
* // signature: foo(I)V
Expand Down

0 comments on commit 1e2f74a

Please sign in to comment.