@@ -317,16 +317,11 @@ ASTfunction_declaration::ASTfunction_declaration (OSLCompilerImpl *comp,
317317 f = NULL ;
318318 }
319319
320- // FIXME -- allow multiple function declarations, but only if they
321- // aren't the same polymorphic type.
322-
323320 if (name[0 ] == ' _' && name[1 ] == ' _' && name[2 ] == ' _' ) {
324321 error (" \" %s\" : sorry, can't start with three underscores" ,
325322 name.c_str ());
326323 }
327324
328- m_sym = new FunctionSymbol (name, type, this );
329- func ()->nextpoly ((FunctionSymbol *)f);
330325 std::string argcodes = oslcompiler->code_from_type (m_typespec);
331326 for (ASTNode *arg = form; arg; arg = arg->nextptr ()) {
332327 const TypeSpec &t (arg->typespec ());
@@ -341,6 +336,36 @@ ASTfunction_declaration::ASTfunction_declaration (OSLCompilerImpl *comp,
341336 v->error (" function parameter '%s' may not have a default initializer." ,
342337 v->name ().c_str ());
343338 }
339+
340+ if (stmts && f && f->symtype () == SymTypeFunction) {
341+ for (FunctionSymbol* poly = static_cast <FunctionSymbol*>(f); poly;
342+ poly = poly->nextpoly ()) {
343+ // If the argcodes match, only one should have statements.
344+ // If there is no ASTNode for the poly, must be a builtin, and has
345+ // 'implicit' statements.
346+ auto other = static_cast <ASTfunction_declaration*>(poly->node ());
347+ if ((!other || other->statements ()) && poly->argcodes () == argcodes) {
348+ ASSERT (argcodes.size () > 0 );
349+ error (" redefinition of %sfunction: %s %s (%s).%s" ,
350+ other ? " " : " builtin " ,
351+ type_c_str (type), m_name,
352+ argcodes.size () <= 1 ? " " :
353+ m_compiler->typelist_from_code (argcodes.c_str ()+1 ),
354+ other ? Strutil::format (
355+ " \n\t\t previous declaration was at %s:%d" ,
356+ OIIO::Filesystem::filename (other->sourcefile ().string ()),
357+ other->sourceline ())
358+ : std::string ());
359+ // Set m_sym to the function that is being overwritten.
360+ m_sym = poly;
361+ return ;
362+ }
363+ }
364+ }
365+
366+ m_sym = new FunctionSymbol (name, type, this );
367+ func ()->nextpoly ((FunctionSymbol *)f);
368+
344369 func ()->argcodes (ustring (argcodes));
345370 oslcompiler->symtab ().insert (m_sym);
346371
0 commit comments