@@ -102,17 +102,17 @@ class BaseTypeMemberVariableDeclaration(
102102 false
103103 }
104104
105- val isMutabilityTiedToParentObject: Boolean =
106- attributes.ownership == BoundBaseTypeMemberVariable .Ownership .OWNED &&
107- variableDeclaration.type?.mutability == null
108-
109105 inner class Binder (val typeRootContext : CTContext ) {
110106 val isConstructorParameterInitialized: Boolean = this @BaseTypeMemberVariableDeclaration.isConstructorParameterInitialized
111- val isMutabilityTiedToParentObject: Boolean = this @BaseTypeMemberVariableDeclaration.isMutabilityTiedToParentObject
112- val mayNeedConstructorTypeParameter: Boolean get()= needsCtorTypeParameter != false
113107
114- private var needsCtorTypeParameter: Boolean? = if (isConstructorParameterInitialized && isMutabilityTiedToParentObject) null /* not yet known*/ else false /* definitely not */
108+ private val isOwned: Boolean = attributes.ownership == BoundBaseTypeMemberVariable .Ownership .OWNED
109+ private var needsCtorTypeParameter: Boolean? = if (isConstructorParameterInitialized && isOwned) null /* not yet known*/ else false /* definitely not */
115110 private var ctorTypeParameter: BoundTypeParameter ? = null
111+ val mayNeedConstructorTypeParameter: Boolean get()= needsCtorTypeParameter != false
112+ private val resolvedType: BoundTypeReference ? by lazy {
113+ variableDeclaration.type?.let (typeRootContext::resolveType)
114+ }
115+ private val isMutabilityTiedToParentObject: Boolean get() = isOwned && resolvedType?.mutability in setOf (null , TypeMutability .top())
116116
117117 fun generateTypeParameterForConstructor (
118118 contextBeforeCtorFunctionRoot : CTContext ,
@@ -131,13 +131,10 @@ class BaseTypeMemberVariableDeclaration(
131131 needsCtorTypeParameter = false
132132 return null
133133 }
134- if (declaredType != null ) {
135- val resolvedType = typeRootContext.resolveType(declaredType)
136- if (resolvedType.mutability != TypeMutability .top()) {
137- // mutability is pre-determined, no need to parameterize the constructor
138- needsCtorTypeParameter = false
139- return null
140- }
134+ if (resolvedType?.mutability !in setOf (null , TypeMutability .top())) {
135+ // mutability is pre-determined, no need to parameterize the constructor
136+ needsCtorTypeParameter = false
137+ return null
141138 }
142139 needsCtorTypeParameter = true
143140
@@ -239,6 +236,7 @@ class BaseTypeMemberVariableDeclaration(
239236 attributes,
240237 baseType,
241238 this @BaseTypeMemberVariableDeclaration,
239+ isMutabilityTiedToParentObject,
242240 )
243241 }
244242
0 commit comments