Skip to content

Commit

Permalink
fix Type.children() to go up namespace chain
Browse files Browse the repository at this point in the history
  • Loading branch information
gewang committed Nov 1, 2024
1 parent 0004053 commit 025217c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
9 changes: 8 additions & 1 deletion VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ ChucK VERSIONS log
suffice, assuming there are no filename conflicts elsewhere in the
import paths)
******************************************************
- (added) member function in Object:
- (added) member function in Object to get the instantiated type of an
object, regardless of the apparent type
Type Object.typeOfInstance()
Get the instanced type of this object.
- (fixed) specific internal UGen connection error now handled without
Expand All @@ -64,6 +65,12 @@ ChucK VERSIONS log
now are distinguished from windows drive letters (e.g., "A:\")
- (fixed) Type.of() now reports more specific array type (e.g.,
`string[]`) instead ofgeneric `@array`
- (fixed) type system [user] namespace now instantiated correctly at
initialization; previously [global] was used until a clearVM was
performed -- this caused incorrect behavior with certain functionality,
including a crash in Type.children(); relatedly a long-standing
bug was fixed in the type system scope::lookup mechanism that added
NULL entries during lookup
- (fixed) modulo `%` by zero (int or float) now throws an exception;
previously this would either produce an incorrect result or cause a
crash
Expand Down
41 changes: 25 additions & 16 deletions src/core/chuck_lang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3452,25 +3452,34 @@ CK_DLL_MFUN( type_children )

// instantiate
Chuck_ArrayInt * ret = new Chuck_ArrayInt( TRUE );
// initialize as chuck object
initialize_object( ret, VM->env()->ckt_array, SHRED, VM );

// results
vector<Chuck_Type *> types;
// get types
VM->env()->nspc_top()->get_types( types );
// clear
// clear the vector
ret->m_vector.clear();
// iterate
for( t_CKINT i = 0; i < types.size(); i++ )

// get the current top-most namespace
Chuck_Namespace * nspc = VM->env()->nspc_top();
// while we have a namespace
while( nspc != NULL )
{
// skip me
if( equals( types[i], me ) ) continue;
// skip if not a subclass of me
if( !isa( types[i], me ) ) continue;
// copy
ret->m_vector.push_back( (t_CKINT)types[i] );
// add reference
CK_SAFE_ADD_REF( types[i] );
// results
vector<Chuck_Type *> types;
// get types
nspc->get_types( types );
// iterate
for( t_CKINT i = 0; i < types.size(); i++ )
{
// skip me
if( equals( types[i], me ) ) continue;
// skip if not a subclass of me
if( !isa( types[i], me ) ) continue;
// append to vector
ret->m_vector.push_back( (t_CKINT)types[i] );
// add reference
CK_SAFE_ADD_REF( types[i] );
}
// go up the namespace, e.g., from [user] to [global]
nspc = nspc->parent;
}

// return
Expand Down

0 comments on commit 025217c

Please sign in to comment.