~ fix shallow dependencies
diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java
index 0290ab6..a22e813 100644
--- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java
+++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java
@@ -16644,6 +16644,12 @@
                 }
 
                 @Test
+                @TestMetadata("bothOuterAndProperConstraints.kt")
+                public void testBothOuterAndProperConstraints() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/bothOuterAndProperConstraints.kt");
+                }
+
+                @Test
                 @TestMetadata("builderPassedAsNamedArgument.kt")
                 public void testBuilderPassedAsNamedArgument() throws Exception {
                     runTest("compiler/testData/diagnostics/tests/inference/builderInference/builderPassedAsNamedArgument.kt");
@@ -16686,6 +16692,24 @@
                 }
 
                 @Test
+                @TestMetadata("fixingTVForLambadaWithShallowDependencyToOuter.kt")
+                public void testFixingTVForLambadaWithShallowDependencyToOuter() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter.kt");
+                }
+
+                @Test
+                @TestMetadata("fixingTVForLambadaWithShallowDependencyToOuter2.kt")
+                public void testFixingTVForLambadaWithShallowDependencyToOuter2() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter2.kt");
+                }
+
+                @Test
+                @TestMetadata("fixingTVForLambadaWithShallowDependencyToOuter3.kt")
+                public void testFixingTVForLambadaWithShallowDependencyToOuter3() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter3.kt");
+                }
+
+                @Test
                 @TestMetadata("incompleteCallInReturnArgumentsWithProperExpectType.kt")
                 public void testIncompleteCallInReturnArgumentsWithProperExpectType() throws Exception {
                     runTest("compiler/testData/diagnostics/tests/inference/builderInference/incompleteCallInReturnArgumentsWithProperExpectType.kt");
diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java
index b776638..bf37244 100644
--- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java
+++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java
@@ -16644,6 +16644,12 @@
                 }
 
                 @Test
+                @TestMetadata("bothOuterAndProperConstraints.kt")
+                public void testBothOuterAndProperConstraints() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/bothOuterAndProperConstraints.kt");
+                }
+
+                @Test
                 @TestMetadata("builderPassedAsNamedArgument.kt")
                 public void testBuilderPassedAsNamedArgument() throws Exception {
                     runTest("compiler/testData/diagnostics/tests/inference/builderInference/builderPassedAsNamedArgument.kt");
@@ -16686,6 +16692,24 @@
                 }
 
                 @Test
+                @TestMetadata("fixingTVForLambadaWithShallowDependencyToOuter.kt")
+                public void testFixingTVForLambadaWithShallowDependencyToOuter() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter.kt");
+                }
+
+                @Test
+                @TestMetadata("fixingTVForLambadaWithShallowDependencyToOuter2.kt")
+                public void testFixingTVForLambadaWithShallowDependencyToOuter2() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter2.kt");
+                }
+
+                @Test
+                @TestMetadata("fixingTVForLambadaWithShallowDependencyToOuter3.kt")
+                public void testFixingTVForLambadaWithShallowDependencyToOuter3() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter3.kt");
+                }
+
+                @Test
                 @TestMetadata("incompleteCallInReturnArgumentsWithProperExpectType.kt")
                 public void testIncompleteCallInReturnArgumentsWithProperExpectType() throws Exception {
                     runTest("compiler/testData/diagnostics/tests/inference/builderInference/incompleteCallInReturnArgumentsWithProperExpectType.kt");
diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java
index 0543f99..e7dc8d4 100644
--- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java
+++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java
@@ -16638,6 +16638,12 @@
                 }
 
                 @Test
+                @TestMetadata("bothOuterAndProperConstraints.kt")
+                public void testBothOuterAndProperConstraints() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/bothOuterAndProperConstraints.kt");
+                }
+
+                @Test
                 @TestMetadata("builderPassedAsNamedArgument.kt")
                 public void testBuilderPassedAsNamedArgument() throws Exception {
                     runTest("compiler/testData/diagnostics/tests/inference/builderInference/builderPassedAsNamedArgument.kt");
@@ -16680,6 +16686,24 @@
                 }
 
                 @Test
+                @TestMetadata("fixingTVForLambadaWithShallowDependencyToOuter.kt")
+                public void testFixingTVForLambadaWithShallowDependencyToOuter() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter.kt");
+                }
+
+                @Test
+                @TestMetadata("fixingTVForLambadaWithShallowDependencyToOuter2.kt")
+                public void testFixingTVForLambadaWithShallowDependencyToOuter2() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter2.kt");
+                }
+
+                @Test
+                @TestMetadata("fixingTVForLambadaWithShallowDependencyToOuter3.kt")
+                public void testFixingTVForLambadaWithShallowDependencyToOuter3() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter3.kt");
+                }
+
+                @Test
                 @TestMetadata("incompleteCallInReturnArgumentsWithProperExpectType.kt")
                 public void testIncompleteCallInReturnArgumentsWithProperExpectType() throws Exception {
                     runTest("compiler/testData/diagnostics/tests/inference/builderInference/incompleteCallInReturnArgumentsWithProperExpectType.kt");
diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java
index 57bfe0c..dd74a30 100644
--- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java
+++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java
@@ -16644,6 +16644,12 @@
                 }
 
                 @Test
+                @TestMetadata("bothOuterAndProperConstraints.kt")
+                public void testBothOuterAndProperConstraints() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/bothOuterAndProperConstraints.kt");
+                }
+
+                @Test
                 @TestMetadata("builderPassedAsNamedArgument.kt")
                 public void testBuilderPassedAsNamedArgument() throws Exception {
                     runTest("compiler/testData/diagnostics/tests/inference/builderInference/builderPassedAsNamedArgument.kt");
@@ -16686,6 +16692,24 @@
                 }
 
                 @Test
+                @TestMetadata("fixingTVForLambadaWithShallowDependencyToOuter.kt")
+                public void testFixingTVForLambadaWithShallowDependencyToOuter() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter.kt");
+                }
+
+                @Test
+                @TestMetadata("fixingTVForLambadaWithShallowDependencyToOuter2.kt")
+                public void testFixingTVForLambadaWithShallowDependencyToOuter2() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter2.kt");
+                }
+
+                @Test
+                @TestMetadata("fixingTVForLambadaWithShallowDependencyToOuter3.kt")
+                public void testFixingTVForLambadaWithShallowDependencyToOuter3() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter3.kt");
+                }
+
+                @Test
                 @TestMetadata("incompleteCallInReturnArgumentsWithProperExpectType.kt")
                 public void testIncompleteCallInReturnArgumentsWithProperExpectType() throws Exception {
                     runTest("compiler/testData/diagnostics/tests/inference/builderInference/incompleteCallInReturnArgumentsWithProperExpectType.kt");
diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt
index 5517947..deee490 100644
--- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt
+++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt
@@ -22,6 +22,7 @@
     private val languageVersionSettings: LanguageVersionSettings
 ) {
     interface Context : TypeSystemInferenceExtensionContext {
+        val notFixedTypeVariables: Map<TypeConstructorMarker, VariableWithConstraints>
         val outerSystemVariablesPrefixSize: Int
         fun isProperType(type: KotlinTypeMarker): Boolean
         fun buildNotFixedVariablesToStubTypesSubstitutor(): TypeSubstitutorMarker
@@ -351,7 +352,7 @@
     }
 
     private fun Context.isProperTypeForFixation(type: KotlinTypeMarker): Boolean =
-        isProperTypeForFixation(type) { isProperType(it) }
+        isProperTypeForFixation(type, { it in notFixedTypeVariables }) { isProperType(it) }
 
     private fun findResultIfThereIsEqualsConstraint(c: Context, variableWithConstraints: VariableWithConstraints): KotlinTypeMarker? =
         with(c) {
diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt
index ef50ea5..910b277 100644
--- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt
+++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt
@@ -101,7 +101,6 @@
         !notFixedTypeVariables.contains(variable) || dependencyProvider.isVariableRelatedToTopLevelType(variable) ||
                 variableHasUnprocessedConstraintsInForks(variable) ->
             TypeVariableFixationReadiness.FORBIDDEN
-        dependencyProvider.isShallowlyRelatedToOuterType(variable) -> TypeVariableFixationReadiness.SHALLOW_OUTER_TYPE_VARIABLE_DEPENDENCY
         isTypeInferenceForSelfTypesSupported && areAllProperConstraintsSelfTypeBased(variable) ->
             TypeVariableFixationReadiness.READY_FOR_FIXATION_DECLARED_UPPER_BOUND_WITH_SELF_TYPES
         !variableHasProperArgumentConstraints(variable) -> TypeVariableFixationReadiness.WITHOUT_PROPER_ARGUMENT_CONSTRAINT
@@ -182,7 +181,7 @@
 
         return when (getTypeVariableReadiness(candidate, dependencyProvider)) {
             TypeVariableFixationReadiness.FORBIDDEN -> null
-            TypeVariableFixationReadiness.WITHOUT_PROPER_ARGUMENT_CONSTRAINT, TypeVariableFixationReadiness.SHALLOW_OUTER_TYPE_VARIABLE_DEPENDENCY -> VariableForFixation(candidate, false)
+            TypeVariableFixationReadiness.WITHOUT_PROPER_ARGUMENT_CONSTRAINT -> VariableForFixation(candidate, false)
             TypeVariableFixationReadiness.DEEP_OUTER_TYPE_VARIABLE_DEPENDENCY ->
                 VariableForFixation(candidate, hasProperConstraint = isRelevantToInputType)
             TypeVariableFixationReadiness.WITH_TRIVIAL_OR_NON_PROPER_CONSTRAINTS ->
@@ -216,7 +215,7 @@
                 && !c.isNullabilityConstraint
 
     private fun Context.isProperType(type: KotlinTypeMarker): Boolean =
-        isProperTypeForFixation(type) { t -> !t.contains { isNotFixedRelevantVariable(it) } }
+        isProperTypeForFixation(type, { it in notFixedTypeVariables }) { t -> !t.contains { isNotFixedRelevantVariable(it) } }
 
     private fun Context.isNotFixedRelevantVariable(it: KotlinTypeMarker): Boolean {
         val key = it.typeConstructor()
@@ -263,8 +262,15 @@
     }
 }
 
-inline fun TypeSystemInferenceExtensionContext.isProperTypeForFixation(type: KotlinTypeMarker, isProper: (KotlinTypeMarker) -> Boolean) =
-    isProper(type) && extractProjectionsForAllCapturedTypes(type).all(isProper)
+inline fun TypeSystemInferenceExtensionContext.isProperTypeForFixation(
+    type: KotlinTypeMarker,
+    isNotFixedTypeVariable: (TypeConstructorMarker) -> Boolean,
+    isProper: (KotlinTypeMarker) -> Boolean
+): Boolean {
+    if (isNotFixedTypeVariable(type.typeConstructor())) return false
+
+    return isProper(type) && extractProjectionsForAllCapturedTypes(type).all(isProper)
+}
 
 fun TypeSystemInferenceExtensionContext.extractProjectionsForAllCapturedTypes(baseType: KotlinTypeMarker): Set<KotlinTypeMarker> {
     if (baseType.isFlexible()) {
diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/bothOuterAndProperConstraints.kt b/compiler/testData/diagnostics/tests/inference/builderInference/bothOuterAndProperConstraints.kt
new file mode 100644
index 0000000..7296066
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/inference/builderInference/bothOuterAndProperConstraints.kt
@@ -0,0 +1,15 @@
+// FIR_IDENTICAL
+class Controller<T> {
+    fun yield(t: T): Boolean = true
+}
+
+fun <S> generate(g: suspend Controller<S>.() -> Unit): S = TODO()
+
+fun <R> foo(w: R, x: (R) -> R): R = TODO()
+
+fun main() {
+    generate {
+        yield(1)
+        yield(foo(2) { 3 })
+    }
+}
\ No newline at end of file
diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter.fir.kt
new file mode 100644
index 0000000..39b4f52
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter.fir.kt
@@ -0,0 +1,37 @@
+class Controller<T> {
+    fun yield(t: T): Boolean = true
+    fun get(): T = TODO()
+}
+
+fun <S> generate(g: suspend Controller<S>.() -> Unit): S = TODO()
+
+interface A {
+    val a: Any
+}
+
+interface B : A {
+    val b: Any
+}
+
+fun <R> myWith(r: R, b: R.() -> Unit) {}
+
+fun main(aI: A, bI: B) {
+    val x = generate {
+        // B <: S
+        yield(bI)
+
+        // S <: R
+        // B <: R
+        // R = B
+        // S = B
+        myWith(get()) {
+            this.a
+            this.b
+        }
+
+        yield(<!ARGUMENT_TYPE_MISMATCH!>aI<!>)
+    }
+
+    x.a
+    x.b
+}
\ No newline at end of file
diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter.kt b/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter.kt
new file mode 100644
index 0000000..d11f319
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter.kt
@@ -0,0 +1,37 @@
+class Controller<T> {
+    fun yield(t: T): Boolean = true
+    fun get(): T = TODO()
+}
+
+fun <S> generate(g: suspend Controller<S>.() -> Unit): S = TODO()
+
+interface A {
+    val a: Any
+}
+
+interface B : A {
+    val b: Any
+}
+
+fun <R> myWith(r: R, b: R.() -> Unit) {}
+
+fun main(aI: A, bI: B) {
+    val x = generate {
+        // B <: S
+        yield(bI)
+
+        // S <: R
+        // B <: R
+        // R = B
+        // S = B
+        myWith(get()) {
+            this.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE, DEBUG_INFO_UNRESOLVED_WITH_TARGET, UNRESOLVED_REFERENCE!>a<!>
+            this.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE, DEBUG_INFO_UNRESOLVED_WITH_TARGET, UNRESOLVED_REFERENCE!>b<!>
+        }
+
+        yield(aI)
+    }
+
+    x.a
+    x.<!UNRESOLVED_REFERENCE!>b<!>
+}
\ No newline at end of file
diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter2.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter2.fir.kt
new file mode 100644
index 0000000..57fa704
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter2.fir.kt
@@ -0,0 +1,24 @@
+class Controller<T> {
+    fun yield(t: T): Boolean = true
+    fun get(): T = TODO()
+}
+
+fun <S> generate(g: suspend Controller<S>.() -> Unit): S = TODO()
+
+fun bar(x: Any) {}
+fun <R> myWith(r: R, b: R.() -> Unit) {}
+
+fun main() {
+    generate {
+        // S <: Any
+        bar(get())
+
+        // S <: R
+        // Any <: R
+        <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>myWith<!>(get()) {
+            <!UNRESOLVED_REFERENCE!>it<!>.length
+        }
+
+        yield(<!ARGUMENT_TYPE_MISMATCH!>""<!>)
+    }.<!UNRESOLVED_REFERENCE!>length<!>
+}
\ No newline at end of file
diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter2.kt b/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter2.kt
new file mode 100644
index 0000000..76f1c7c
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter2.kt
@@ -0,0 +1,24 @@
+class Controller<T> {
+    fun yield(t: T): Boolean = true
+    fun get(): T = TODO()
+}
+
+fun <S> generate(g: suspend Controller<S>.() -> Unit): S = TODO()
+
+fun bar(x: Any) {}
+fun <R> myWith(r: R, b: R.() -> Unit) {}
+
+fun main() {
+    generate {
+        // S <: Any
+        bar(get())
+
+        // S <: R
+        // Any <: R
+        myWith(get()) {
+            <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE, DEBUG_INFO_UNRESOLVED_WITH_TARGET, UNRESOLVED_REFERENCE!>it<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>length<!>
+        }
+
+        yield("")
+    }.length
+}
\ No newline at end of file
diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter3.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter3.fir.kt
new file mode 100644
index 0000000..c0be1ce
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter3.fir.kt
@@ -0,0 +1,32 @@
+class Controller<T> {
+    fun yield(t: T): Boolean = true
+    fun get(): T = TODO()
+}
+
+fun <S> generate(g: suspend Controller<S>.() -> Unit): S = TODO()
+
+fun <R> foo(w: R, x: (R) -> R): R = TODO()
+
+fun <Q> materialize(): Q = TODO()
+
+fun bar(x: String) {}
+
+fun main() {
+    generate {
+        // S <: String
+        bar(get())
+        // R <: S
+        // R <: String
+        // R = String
+        yield(foo(materialize()) { it.length.toString() })
+    }
+
+    generate {
+        // String <: S
+        yield("")
+        // S <: R
+        // => String <: R
+        // R = CST(S, String) = String
+        foo(get()) { it.length.toString() }
+    }
+}
\ No newline at end of file
diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter3.kt b/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter3.kt
new file mode 100644
index 0000000..d5d656f
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter3.kt
@@ -0,0 +1,32 @@
+class Controller<T> {
+    fun yield(t: T): Boolean = true
+    fun get(): T = TODO()
+}
+
+fun <S> generate(g: suspend Controller<S>.() -> Unit): S = TODO()
+
+fun <R> foo(w: R, x: (R) -> R): R = TODO()
+
+fun <Q> materialize(): Q = TODO()
+
+fun bar(x: String) {}
+
+fun main() {
+    generate {
+        // S <: String
+        bar(get())
+        // R <: S
+        // R <: String
+        // R = String
+        yield(foo(materialize()) { it.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE, DEBUG_INFO_UNRESOLVED_WITH_TARGET, UNRESOLVED_REFERENCE!>length<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>toString<!>() })
+    }
+
+    generate {
+        // String <: S
+        yield("")
+        // S <: R
+        // => String <: R
+        // R = CST(S, String) = String
+        foo(<!TYPE_MISMATCH, TYPE_MISMATCH!>get()<!>) { it.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE, DEBUG_INFO_UNRESOLVED_WITH_TARGET, UNRESOLVED_REFERENCE!>length<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>toString<!>() }
+    }
+}
\ No newline at end of file
diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/kt49828.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/kt49828.fir.kt
index aa55e45..44549d6 100644
--- a/compiler/testData/diagnostics/tests/inference/builderInference/kt49828.fir.kt
+++ b/compiler/testData/diagnostics/tests/inference/builderInference/kt49828.fir.kt
@@ -81,26 +81,26 @@
     val list7 = buildList {
         add("one")
 
-        <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!> (get(0)) {
-            <!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!>()
+        with (get(0)) {
+            bar()
         }
     }
     val list71 = buildList {
         add("one")
 
-        <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!> (get(0)) l1@ {
-            with (<!ARGUMENT_TYPE_MISMATCH!>listOf(1)<!>) <!ARGUMENT_TYPE_MISMATCH!>{
-                <!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!>()
-            }<!>
+        with (get(0)) l1@ {
+            with (listOf(1)) {
+                bar()
+            }
         }
     }
     val list711 = buildList {
         add("one")
 
-        <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!> (get(0)) {
-            with (<!ARGUMENT_TYPE_MISMATCH!>listOf(1)<!>) <!ARGUMENT_TYPE_MISMATCH!>{
-                <!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!>()
-            }<!>
+        with (get(0)) {
+            with (listOf(1)) {
+                bar()
+            }
         }
     }
     val list8 = buildList {
@@ -111,19 +111,19 @@
     val list9 = buildList {
         add("one")
 
-        <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!> (get(0)) {
-            with (<!ARGUMENT_TYPE_MISMATCH!><!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>Inv<!>(<!CANNOT_INFER_PARAMETER_TYPE!>this<!>)<!>) <!ARGUMENT_TYPE_MISMATCH!>{
-                <!OVERLOAD_RESOLUTION_AMBIGUITY!>foo2<!>()
-            }<!>
+        with (get(0)) {
+            with (Inv(this)) {
+                foo2()
+            }
         }
     }
     val list91 = buildList {
         add("one")
 
-        <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!> (get(0)) {
-            with (<!ARGUMENT_TYPE_MISMATCH!><!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>Inv<!>(<!CANNOT_INFER_PARAMETER_TYPE!>this<!>)<!>) <!ARGUMENT_TYPE_MISMATCH!>{
-                <!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!>()
-            }<!>
+        with (get(0)) {
+            with (Inv(this)) {
+                bar()
+            }
         }
     }
 
@@ -160,8 +160,8 @@
     val list17 = buildList l1@ {
         add("one")
 
-        <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!> (get(0)) {
-            <!NONE_APPLICABLE!>foo0003<!>(0f, this@l1.get(<!ARGUMENT_TYPE_MISMATCH!>0<!>))
+        with (get(0)) {
+            foo0003(0f, <!ARGUMENT_TYPE_MISMATCH!>this@l1.get(0)<!>)
         }
     }
 
@@ -206,18 +206,18 @@
 fun <L, K, V> twoBuilderLambdas(@BuilderInference block: Foo<L>.() -> Unit, @BuilderInference block2: Foo2<K, V>.() -> Unit) {}
 
 fun test() {
-    <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>twoBuilderLambdas<!>(
+    twoBuilderLambdas(
         {
             add("")
-            <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!> (get()) {
-                with (<!ARGUMENT_TYPE_MISMATCH!>listOf(1)<!>) <!ARGUMENT_TYPE_MISMATCH!>{
-                    <!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!>()
-                }<!>
+            with (get()) {
+                with (listOf(1)) {
+                    bar()
+                }
             }
         },
         {
-            put(<!ARGUMENT_TYPE_MISMATCH!>1<!>, <!ARGUMENT_TYPE_MISMATCH!>"one"<!>)
-            <!NONE_APPLICABLE!>foo11<!>(entries())
+            put(1, "one")
+            foo11(entries())
         }
     )
 }
diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/lambdaParameterTypeFixation.kt b/compiler/testData/diagnostics/tests/inference/builderInference/lambdaParameterTypeFixation.kt
index 0a5f978..580f671 100644
--- a/compiler/testData/diagnostics/tests/inference/builderInference/lambdaParameterTypeFixation.kt
+++ b/compiler/testData/diagnostics/tests/inference/builderInference/lambdaParameterTypeFixation.kt
@@ -8,7 +8,7 @@
 fun foo() {
     val t = generate {
         yield("")
-        <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar<!>(this, "") { it.<!UNRESOLVED_REFERENCE!>length<!> }
+        bar(this, "") { it.length }
     }
 
     <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>t<!>
diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java
index 80684ec..20a962f 100644
--- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java
+++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java
@@ -16644,6 +16644,12 @@
                 }
 
                 @Test
+                @TestMetadata("bothOuterAndProperConstraints.kt")
+                public void testBothOuterAndProperConstraints() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/bothOuterAndProperConstraints.kt");
+                }
+
+                @Test
                 @TestMetadata("builderPassedAsNamedArgument.kt")
                 public void testBuilderPassedAsNamedArgument() throws Exception {
                     runTest("compiler/testData/diagnostics/tests/inference/builderInference/builderPassedAsNamedArgument.kt");
@@ -16686,6 +16692,24 @@
                 }
 
                 @Test
+                @TestMetadata("fixingTVForLambadaWithShallowDependencyToOuter.kt")
+                public void testFixingTVForLambadaWithShallowDependencyToOuter() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter.kt");
+                }
+
+                @Test
+                @TestMetadata("fixingTVForLambadaWithShallowDependencyToOuter2.kt")
+                public void testFixingTVForLambadaWithShallowDependencyToOuter2() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter2.kt");
+                }
+
+                @Test
+                @TestMetadata("fixingTVForLambadaWithShallowDependencyToOuter3.kt")
+                public void testFixingTVForLambadaWithShallowDependencyToOuter3() throws Exception {
+                    runTest("compiler/testData/diagnostics/tests/inference/builderInference/fixingTVForLambadaWithShallowDependencyToOuter3.kt");
+                }
+
+                @Test
                 @TestMetadata("incompleteCallInReturnArgumentsWithProperExpectType.kt")
                 public void testIncompleteCallInReturnArgumentsWithProperExpectType() throws Exception {
                     runTest("compiler/testData/diagnostics/tests/inference/builderInference/incompleteCallInReturnArgumentsWithProperExpectType.kt");