Changeset e58dfb9


Ignore:
Timestamp:
Feb 14, 2017, 1:53:29 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
35cd219, eed5e48
Parents:
97d246d
Message:

Fix scoping bug with generic type instantiations (thanks Rob!)

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Common/ScopedMap.h

    r97d246d re58dfb9  
    230230        }
    231231
     232        /// Finds the given key in the provided scope; returns end() for none such
     233        iterator findAt( size_type scope, const Key& key ) {
     234                typename Scope::iterator val = scopes[scope].find( key );
     235                if ( val != scopes[scope].end() ) return iterator( scopes, val, scope );
     236                return end();
     237        }
     238        const_iterator findAt( size_type scope, const Key& key ) const {
     239                return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->findAt( scope, key ) );
     240        }
     241
    232242        /// Finds the given key in the outermost scope inside the given scope where it occurs
    233243        iterator findNext( const_iterator &it, const Key &key ) {
  • src/GenPoly/InstantiateGeneric.cc

    r97d246d re58dfb9  
    122122                /// Adds a value for a (key, typeList) pair to the current scope
    123123                void insert( Key *key, const std::list< TypeExpr* > &params, Value *value ) {
    124                         instantiations[ key ].push_back( Instantiation( TypeList( params ), value ) );
     124                        auto it = instantiations.findAt( instantiations.currentScope(), key );
     125                        if ( it == instantiations.end() ) {
     126                                instantiations.insert( key, ValueList{ Instantiation{ TypeList( params ), value } } );
     127                        } else {
     128                                it->second.push_back( Instantiation{ TypeList( params ), value } );
     129                        }
    125130                }
    126131        };
Note: See TracChangeset for help on using the changeset viewer.