@@ -99,29 +99,19 @@ private PythonClassType CreateClass(ClassDefinition cd) {
99
99
100
100
private void AddFunctionOrProperty ( FunctionDefinition fd ) {
101
101
var declaringType = fd . Parent != null && _typeMap . TryGetValue ( fd . Parent , out var t ) ? t : null ;
102
- var existing = _eval . LookupNameInScopes ( fd . Name , LookupOptions . Local ) ;
103
-
104
- switch ( existing ? . MemberType ) {
105
- case PythonMemberType . Method :
106
- case PythonMemberType . Function :
107
- case PythonMemberType . Property :
108
- ReportRedefinedFunction ( fd , existing as PythonType ) ;
109
- break ;
110
- }
111
-
112
- if ( ! TryAddProperty ( fd , existing , declaringType ) ) {
113
- AddFunction ( fd , existing , declaringType ) ;
102
+ if ( ! TryAddProperty ( fd , declaringType ) ) {
103
+ AddFunction ( fd , declaringType ) ;
114
104
}
115
105
}
116
106
117
- private void AddFunction ( FunctionDefinition fd , IMember existing , IPythonType declaringType ) {
118
- if ( ! ( existing is PythonFunctionType f ) ) {
119
- f = new PythonFunctionType ( fd , declaringType , _eval . GetLocationOfName ( fd ) ) ;
107
+ private void AddFunction ( FunctionDefinition fd , IPythonType declaringType ) {
108
+ if ( ! ( _eval . LookupNameInScopes ( fd . Name , LookupOptions . Local ) is PythonFunctionType existing ) ) {
109
+ existing = new PythonFunctionType ( fd , declaringType , _eval . GetLocationOfName ( fd ) ) ;
120
110
// The variable is transient (non-user declared) hence it does not have location.
121
111
// Function type is tracking locations for references and renaming.
122
- _eval . DeclareVariable ( fd . Name , f , VariableSource . Declaration ) ;
112
+ _eval . DeclareVariable ( fd . Name , existing , VariableSource . Declaration ) ;
123
113
}
124
- AddOverload ( fd , f , o => f . AddOverload ( o ) ) ;
114
+ AddOverload ( fd , existing , o => existing . AddOverload ( o ) ) ;
125
115
}
126
116
127
117
private void AddOverload ( FunctionDefinition fd , IPythonClassMember function , Action < IPythonFunctionOverload > addOverload ) {
@@ -159,31 +149,31 @@ private PythonFunctionOverload GetOverloadFromStub(FunctionDefinition node) {
159
149
return null ;
160
150
}
161
151
162
- private bool TryAddProperty ( FunctionDefinition node , IMember existing , IPythonType declaringType ) {
152
+ private bool TryAddProperty ( FunctionDefinition node , IPythonType declaringType ) {
163
153
var dec = node . Decorators ? . Decorators ;
164
154
var decorators = dec != null ? dec . ExcludeDefault ( ) . ToArray ( ) : Array . Empty < Expression > ( ) ;
165
155
166
156
foreach ( var d in decorators . OfType < NameExpression > ( ) ) {
167
157
switch ( d . Name ) {
168
158
case @"property" :
169
- AddProperty ( node , existing , declaringType , false ) ;
159
+ AddProperty ( node , declaringType , false ) ;
170
160
return true ;
171
161
case @"abstractproperty" :
172
- AddProperty ( node , existing , declaringType , true ) ;
162
+ AddProperty ( node , declaringType , true ) ;
173
163
return true ;
174
164
}
175
165
}
176
166
return false ;
177
167
}
178
168
179
- private void AddProperty ( FunctionDefinition fd , IMember existing , IPythonType declaringType , bool isAbstract ) {
180
- if ( ! ( existing is PythonPropertyType p ) ) {
181
- p = new PythonPropertyType ( fd , _eval . GetLocationOfName ( fd ) , declaringType , isAbstract ) ;
169
+ private void AddProperty ( FunctionDefinition fd , IPythonType declaringType , bool isAbstract ) {
170
+ if ( ! ( _eval . LookupNameInScopes ( fd . Name , LookupOptions . Local ) is PythonPropertyType existing ) ) {
171
+ existing = new PythonPropertyType ( fd , _eval . GetLocationOfName ( fd ) , declaringType , isAbstract ) ;
182
172
// The variable is transient (non-user declared) hence it does not have location.
183
173
// Property type is tracking locations for references and renaming.
184
- _eval . DeclareVariable ( fd . Name , p , VariableSource . Declaration ) ;
174
+ _eval . DeclareVariable ( fd . Name , existing , VariableSource . Declaration ) ;
185
175
}
186
- AddOverload ( fd , p , o => p . AddOverload ( o ) ) ;
176
+ AddOverload ( fd , existing , o => existing . AddOverload ( o ) ) ;
187
177
}
188
178
189
179
private IMember GetMemberFromStub ( string name ) {
@@ -213,22 +203,6 @@ private IMember GetMemberFromStub(string name) {
213
203
return member ;
214
204
}
215
205
216
- private void ReportRedefinedFunction ( FunctionDefinition redefined , ILocatedMember existing ) {
217
- // get line number of existing function for diagnostic message
218
- var existingLoc = existing . Definition ;
219
- var existingLine = existingLoc . Span . Start . Line ;
220
-
221
- _eval . ReportDiagnostics (
222
- _eval . Module . Uri ,
223
- new DiagnosticsEntry (
224
- Resources . FunctionRedefined . FormatInvariant ( existingLine ) ,
225
- // only highlight the redefined name
226
- _eval . GetLocationInfo ( redefined . NameExpression ) . Span ,
227
- ErrorCodes . FunctionRedefined ,
228
- Parsing . Severity . Error ,
229
- DiagnosticSource . Analysis ) ) ;
230
- }
231
-
232
206
private static bool IsDeprecated ( ClassDefinition cd )
233
207
=> cd . Decorators ? . Decorators != null && IsDeprecated ( cd . Decorators . Decorators ) ;
234
208
0 commit comments