File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Impl/Specializations/Typing/Types Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -128,11 +128,15 @@ public IMember CreateInstance(IArgumentSet args) {
128
128
throw new ArgumentException ( @"Generic type instance construction arguments must be all of IPythonType" , nameof ( args ) ) ;
129
129
}
130
130
var specific = CreateSpecificType ( args ) ;
131
- return specific == null
131
+ return specific == null || IsSameType ( specific )
132
132
? DeclaringModule . Interpreter . UnknownType . CreateInstance ( args )
133
133
: specific . CreateInstance ( args ) ;
134
134
}
135
135
136
+ private bool IsSameType ( IPythonType specific )
137
+ => specific . MemberType == PythonMemberType . Generic &&
138
+ this . Name == specific . Name ;
139
+
136
140
public IMember Call ( IPythonInstance instance , string memberName , IArgumentSet args ) => DeclaringModule . Interpreter . UnknownType ;
137
141
public IMember Index ( IPythonInstance instance , IArgumentSet args ) => DeclaringModule . Interpreter . UnknownType ;
138
142
Original file line number Diff line number Diff line change 13
13
// See the Apache Version 2.0 License for specific language governing
14
14
// permissions and limitations under the License.
15
15
16
+ using System ;
16
17
using System . Linq ;
17
18
using System . Threading . Tasks ;
18
19
using FluentAssertions ;
@@ -1412,6 +1413,23 @@ import pathlib
1412
1413
analysis . Should ( ) . HaveVariable ( "root" ) . OfType ( "Path" ) ;
1413
1414
analysis . Should ( ) . HaveVariable ( "subdir" ) . OfType ( "PurePath" ) ;
1414
1415
analysis . Should ( ) . HaveVariable ( "child" ) . OfType ( "PurePath" ) ;
1416
+ }
1417
+
1418
+ [ TestMethod , Priority ( 0 ) ]
1419
+ public async Task GenericStackOverflowBub ( ) {
1420
+ /*
1421
+ * Apiiro fix.
1422
+ * The code below created stack overflow if SpecializedGenericType.CreateInstance
1423
+ * Just checking we are not crushing here.
1424
+ */
1425
+ const string code = @"
1426
+ from typing import Union, Sequence, TypeVar
1427
+ _T = TypeVar(""_T"")
1428
+ _NestedSequence = Sequence[Sequence[_T]]
1429
+ _ArrayLike = _NestedSequence[_T]
1430
+ " ;
1431
+ await GetAnalysisAsync ( code , PythonVersions . Python37 ) ;
1432
+ Assert . IsTrue ( true ) ;
1415
1433
}
1416
1434
}
1417
1435
}
You can’t perform that action at this time.
0 commit comments