Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

K2: a secondary constructor's body is never converted

Đã đóng
#174 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, kotlin
Lĩnh vực
compilers

Hướng nghiên cứu

Start in KotlinScan.finalizeType, where each constructor body is assembled as delegation call, parameter-property assignments, then planned init blocks, and look at how runsInitOf decides which constructor runs the init blocks. Then in maddi-kotlin-k2 find where the primary constructor's body is converted and mirror it for KtSecondaryConstructor.bodyBlockExpression, appending it after the current prefix. ConstructorParameterNamedAsPropertyTest deliberately avoids a secondary constructor with a body, so extend it (or add a sibling test) with the snippet from the issue and check that n reads as assigned. Done means a secondary constructor's own body statements appear in the CST after the delegation call and init blocks.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

The K2 front-end never converts a secondary constructor's block body. Given

class Secondary {
    val n: Int
    constructor(n: Int) { this.n = n + 1 }
}

the constructor's CST body is empty. KotlinScan.finalizeType builds every constructor body as: the explicit this(..)/super(..) invocation, then the parameter-property assignments, then the init blocks planned for it. Nothing in maddi-kotlin-k2 reads KtSecondaryConstructor.bodyBlockExpression. Only the delegation call of a secondary constructor survives.

Consequence: the body's assignments, calls and modifications are invisible to the analysis. Above, n is never assigned. A field assigned only there looks unassigned, and a parameter modified only there looks unmodified. That is the unsafe direction.

What kotlinc does: a secondary constructor runs its delegation call; when that is super(..) (or implicit), it then runs the property initializers and init blocks. Its own body comes last. A body converted after the current prefix and planned init blocks matches that order (runsInitOf already picks the constructor that runs the init blocks).

Found while fixing the same-name parameter assignment (CodeLaser/maddi-mod#73). ConstructorParameterNamedAsPropertyTest avoids a secondary constructor with a body for that reason.

Ngôn ngữ chính
Java
Star
1
Fork
1
Merge trung bình
1 giờ 55 phút
Pull request đã merge (30 ngày)
8

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của CodeLaser/maddi

Tất cả issue của CodeLaser/maddi

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.