CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 659
Crash when accessing static hidden methods from zero touch nodes #11238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
844ab8a
e16dd67
442ba90
e8065d0
bfbbf99
c4a9028
be10e65
0c6f2ea
fc44db9
2307cf4
d7a6eea
9944c02
2f55cd0
5ccafff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,23 +213,6 @@ public override string ToString() | |
} | ||
} | ||
|
||
// | ||
/// <summary> | ||
/// Comparer class that defines methods to support the comparison of StaticMirror objects for equality. | ||
/// </summary> | ||
internal class StaticMirrorNameComparer : IEqualityComparer<StaticMirror> | ||
{ | ||
public bool Equals(StaticMirror x, StaticMirror y) | ||
{ | ||
return x.Name == y.Name; | ||
} | ||
|
||
public int GetHashCode(StaticMirror obj) | ||
{ | ||
return obj.Name.GetHashCode(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// A ClassMirror object reflects upon the type of a single designscript variable | ||
/// The information here is populated during the code generation phase | ||
|
@@ -352,33 +335,27 @@ internal ClassMirror(StackValue svData, ProtoCore.Core core) | |
} | ||
|
||
/// <summary> | ||
/// Returns the constructors and static methods and properties | ||
/// belonging to the type and its base types | ||
/// Excludes hidden methods and properties from base types. | ||
/// Returns a list of constructors and static methods and properties | ||
/// belonging to the type and its base types. Filters out repeating names. | ||
/// </summary> | ||
/// <returns></returns> | ||
public IEnumerable<StaticMirror> GetMembers() | ||
{ | ||
// TODO: Factor out reflection functionality for both LibraryServices and Mirrors | ||
List<StaticMirror> members = new List<StaticMirror>(); | ||
members.AddRange(GetConstructors().GroupBy(x => x.Name).Select(y => y.First())); | ||
members.AddRange(GetFunctions().Where(m => m.IsStatic).GroupBy(x => x.Name).Select(y => y.First())); | ||
members.AddRange(GetProperties().Where(m => m.IsStatic).GroupBy(x => x.Name).Select(y => y.First())); | ||
members.AddRange(GetConstructors()); | ||
members.AddRange(GetFunctions().Where(m => m.IsStatic)); | ||
members.AddRange(GetProperties().Where(m => m.IsStatic)); | ||
|
||
// Filter out hidden functions/properties: | ||
// Create a set of unique function, property and constructor descriptions. | ||
// In this case we use ToString() to get the uniques description of the members (func signature, property names, constructor names). | ||
var derivedClassMembers = new HashSet<string>(); | ||
members.ForEach(x => derivedClassMembers.Add(x.ToString())); | ||
|
||
IEnumerable<ClassMirror> baseClasses = this.GetClassHierarchy(); | ||
IEnumerable<ClassMirror> baseClasses = GetClassHierarchy(); | ||
foreach (var baseClass in baseClasses) | ||
{ | ||
members.AddRange(baseClass.GetFunctions().Where(m => m.IsStatic && !derivedClassMembers.Contains(m.ToString())).GroupBy(x => x.Name).Select(y => y.First())); | ||
members.AddRange(baseClass.GetProperties().Where(m => m.IsStatic && !derivedClassMembers.Contains(m.ToString())).GroupBy(x => x.Name).Select(y => y.First())); | ||
members.AddRange(baseClass.GetFunctions().Where(m => m.IsStatic)); | ||
members.AddRange(baseClass.GetProperties().Where(m => m.IsStatic)); | ||
} | ||
|
||
return members; | ||
// Return a list of members with unique names. | ||
return members.GroupBy(x => x.Name).Select(x => x.First()).ToList(); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -499,16 +476,16 @@ public IEnumerable<MethodMirror> GetOverloads(string methodName) | |
public IEnumerable<MethodMirror> GetOverloadsOnType(string methodName) | ||
{ | ||
List<MethodMirror> members = new List<MethodMirror>(); | ||
members.AddRange(this.GetConstructors().Where(x => x.MethodName == methodName)); | ||
members.AddRange(this.GetFunctions().Where(x => x.IsStatic && x.MethodName == methodName)); | ||
members.AddRange(GetConstructors().Where(x => x.MethodName == methodName)); | ||
members.AddRange(GetFunctions().Where(x => x.IsStatic && x.MethodName == methodName)); | ||
|
||
// Filter out hidden functions/properties: | ||
// Create a set of unique function and constructor descriptions. | ||
// In this case we use ToString() to get the uniques description of the members (func signature, constructor names). | ||
// In this case we use ToString() to get the unique description of the members (func signature, constructor names). | ||
var derivedClassMembers = new HashSet<string>(); | ||
members.ForEach(x => derivedClassMembers.Add(x.ToString())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you going to make the same simplification in this commit over here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
IEnumerable<ClassMirror> baseClasses = this.GetClassHierarchy(); | ||
IEnumerable<ClassMirror> baseClasses = GetClassHierarchy(); | ||
foreach (var baseClass in baseClasses) | ||
{ | ||
members.AddRange(baseClass.GetFunctions().Where(x => x.IsStatic && x.MethodName == methodName && !derivedClassMembers.Contains(x.ToString()))); | ||
|
@@ -526,42 +503,37 @@ public IEnumerable<MethodMirror> GetOverloadsOnType(string methodName) | |
public IEnumerable<MethodMirror> GetOverloadsOnInstance(string methodName) | ||
{ | ||
List<MethodMirror> members = new List<MethodMirror>(); | ||
IEnumerable<ClassMirror> baseClasses = this.GetClassHierarchy(); | ||
IEnumerable<ClassMirror> baseClasses = GetClassHierarchy(); | ||
foreach (var baseClass in baseClasses) | ||
{ | ||
members.AddRange(baseClass.GetFunctions().Where(x => !x.IsStatic && x.MethodName == methodName)); | ||
} | ||
|
||
members.AddRange(this.GetFunctions().Where(x => !x.IsStatic && x.MethodName == methodName)); | ||
members.AddRange(GetFunctions().Where(x => !x.IsStatic && x.MethodName == methodName)); | ||
return members; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the instance methods and properties | ||
/// belonging to the type and its base types | ||
/// Excludes hidden methods and properties from base types. | ||
/// belonging to the type and its base types. Filters out repeating names. | ||
/// </summary> | ||
pinzart90 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public IEnumerable<StaticMirror> GetInstanceMembers() | ||
{ | ||
// TODO: Factor out reflection functionality for both LibraryServices and Mirrors | ||
List<StaticMirror> members = new List<StaticMirror>(); | ||
members.AddRange(this.GetFunctions().Where(m => !m.IsStatic).GroupBy(x => x.Name).Select(y => y.First())); | ||
members.AddRange(this.GetProperties().Where(m => !m.IsStatic).GroupBy(x => x.Name).Select(y => y.First())); | ||
|
||
// Filter out hidden functions/properties: | ||
// Create a set of unique function and property descriptions. | ||
// In this case we use ToString() to get the uniques description of the members (func signature, property names). | ||
var derivedClassMembers = new HashSet<string>(); | ||
members.ForEach(x => derivedClassMembers.Add(x.ToString())); | ||
List<StaticMirror> members = new List<StaticMirror>(); | ||
members.AddRange(GetFunctions().Where(m => !m.IsStatic)); | ||
members.AddRange(GetProperties().Where(m => !m.IsStatic)); | ||
|
||
IEnumerable<ClassMirror> baseClasses = this.GetClassHierarchy(); | ||
IEnumerable<ClassMirror> baseClasses = GetClassHierarchy(); | ||
foreach (var baseClass in baseClasses) | ||
{ | ||
members.AddRange(baseClass.GetFunctions().Where(m => !m.IsStatic && !derivedClassMembers.Contains(m.ToString())).GroupBy(x => x.Name).Select(y => y.First())); | ||
members.AddRange(baseClass.GetProperties().Where(m => !m.IsStatic && !derivedClassMembers.Contains(m.ToString())).GroupBy(x => x.Name).Select(y => y.First())); | ||
members.AddRange(baseClass.GetFunctions().Where(m => !m.IsStatic)); | ||
members.AddRange(baseClass.GetProperties().Where(m => !m.IsStatic)); | ||
} | ||
|
||
return members; | ||
// Return a list of members with unique names. | ||
return members.GroupBy(x => x.Name).Select(y => y.First()).ToList(); | ||
} | ||
|
||
public ClassAttributes GetClassAttributes() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Autodesk.DesignScript.Runtime; | ||
pinzart90 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
namespace FFITarget | ||
{ | ||
public class BaseTestHiddenMethods | ||
{ | ||
public static int SomeVariable = 100; | ||
public BaseTestHiddenMethods() | ||
{ | ||
} | ||
|
||
public static int SomeStaticMethod() | ||
{ | ||
return 100; | ||
} | ||
public static int SomeStaticMethod(int[] x) | ||
{ | ||
return 100; | ||
} | ||
public static int SomeStaticMethod(int[] x, int[] y) | ||
{ | ||
return 100; | ||
} | ||
public static int SomeMethod() | ||
{ | ||
return 100; | ||
} | ||
} | ||
|
||
public class DerivedTestHiddenMethods : BaseTestHiddenMethods | ||
{ | ||
public static new int SomeVariable = 200; | ||
public DerivedTestHiddenMethods() | ||
{ | ||
} | ||
public static new int SomeStaticMethod() | ||
{ | ||
return 200; | ||
} | ||
public static new int SomeStaticMethod(int[] x) | ||
{ | ||
return 200; | ||
} | ||
public static new int SomeStaticMethod(int[] x, int[] y) | ||
{ | ||
return 200; | ||
} | ||
public static new int SomeMethod() | ||
{ | ||
return 200; | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we were filtering out members with duplicate names within the scope of each class by use of
.GroupBy(x => x.Name).Select(y => y.First())
I moved the filtering logic at the end so that we remove duplicates across all class hierarchies .