Skip to content

fix(abc/kotlin): primary-constructor superclass call is not a branch #1384

Description

@dekobon

Summary

Kotlin ABC counts a secondary-constructor superclass delegation
(constructor_delegation_call, : super(x)) as a branch but not the
primary-constructor form (constructor_invocation, class Sub : Base(1, 2)). Both invoke the superclass constructor at run time.
#1279 added the first and did not name the second.

Measured

bca metrics --no-config -O json, abc.branches:

class Sub1 : Base(1, 2) { }
class Sub2 : Base { constructor(x: Int) : super(x) { } }
space abc.branches
Sub1 0
Sub2 1

bca dump shows the two productions:

{delegation_specifier:167} : Base(1, 2)
  {constructor_invocation:162} : Base(1, 2)      <- not counted
...
{constructor_delegation_call:154} : super(x)     <- counted

Where

kotlin_count_token_branch / the branch arm in
src/metrics/abc/kotlin.rs lists CallExpression,
ConstructorDelegationCall and the object-construction kinds, but not
ConstructorInvocation.

Sibling comparison

  • C#: constructor_initializer (: base(…) / : this(…)) counts —
    added by fix(abc): constructor delegation calls score zero branches in Java and C# #1279 and pinned by
    csharp_constructor_initializer_is_a_branch.
  • Java and Groovy: class Sub extends Base carries no argument list, so
    there is no analogous production to miss; their super(1) inside a
    constructor body is a CallExpression and already counts.

Kotlin's primary-constructor form is the only spelling of "call the
superclass constructor" that scores zero.

Notes

Found while fixing #1297 (kotlin_super_type_argument_is_not_a_condition
uses class B : A() as scaffolding and its branches_sum() anchor
measured 1, not 2). Not fixed there — it is a branches question, not a
conditions one, and unrelated to the < / > token class that issue
covers.

ConstructorInvocation also appears in an enum-entry initialiser
(enum class E { A(1) }) and a delegation specifier with no arguments
is a plain user_type, not a constructor_invocation, so the arm can
be added without a parent gate — but confirm that with a bca dump
sweep before landing it, and check the nom / wmc / cyclomatic
siblings for the same omission.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions