"field": control of accessor parameter name shadowing, test
This commit is contained in:
@@ -379,6 +379,7 @@ public interface Errors {
|
||||
// General
|
||||
|
||||
DiagnosticFactory1<PsiElement, String> NAME_SHADOWING = DiagnosticFactory1.create(WARNING, PositioningStrategies.FOR_REDECLARATION);
|
||||
DiagnosticFactory0<PsiElement> ACCESSOR_PARAMETER_NAME_SHADOWING = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
DiagnosticFactory0<JetExpression> TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
|
||||
+1
@@ -114,6 +114,7 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(REDECLARATION, "Redeclaration: {0}", STRING);
|
||||
MAP.put(NAME_SHADOWING, "Name shadowed: {0}", STRING);
|
||||
MAP.put(ACCESSOR_PARAMETER_NAME_SHADOWING, "Accessor parameter name 'field' is shadowed by backing field variable");
|
||||
|
||||
MAP.put(TYPE_MISMATCH, "Type mismatch: inferred type is {1} but {0} was expected", RENDER_TYPE, RENDER_TYPE);
|
||||
MAP.put(INCOMPATIBLE_MODIFIERS, "Modifier ''{0}'' is incompatible with ''{1}''", TO_STRING, TO_STRING);
|
||||
|
||||
@@ -779,6 +779,11 @@ public class BodyResolver {
|
||||
SyntheticFieldDescriptor fieldDescriptor = new SyntheticFieldDescriptor(accessorDescriptor, property);
|
||||
WritableScopeStorage innerScopeStorage = (WritableScopeStorage) innerScope;
|
||||
innerScopeStorage.addVariableOrClassDescriptor(fieldDescriptor);
|
||||
for (JetParameter parameter : function.getValueParameters()) {
|
||||
if (SyntheticFieldDescriptor.NAME.equals(parameter.getNameAsName())) {
|
||||
trace.report(Errors.ACCESSOR_PARAMETER_NAME_SHADOWING.on(parameter));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DataFlowInfo dataFlowInfo = null;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
var y: Int = 1
|
||||
|
||||
// No backing field!
|
||||
<!MUST_BE_INITIALIZED!>var x: Int<!>
|
||||
get() = y
|
||||
set(<!ACCESSOR_PARAMETER_NAME_SHADOWING!>field<!>) {
|
||||
y = field
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public var x: kotlin.Int
|
||||
public var y: kotlin.Int
|
||||
@@ -1326,6 +1326,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("FieldAsParam.kt")
|
||||
public void testFieldAsParam() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/backingField/FieldAsParam.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("FieldAsProperty.kt")
|
||||
public void testFieldAsProperty() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/backingField/FieldAsProperty.kt");
|
||||
|
||||
Reference in New Issue
Block a user