@@ -324,14 +324,20 @@ ASTnamed_symbol::ASTnamed_symbol (NodeType node_type, OSLCompilerImpl *comp,
324324
325325
326326
327- void
327+ bool
328328ASTnamed_symbol::check_reserved (ustring name, OSLCompilerImpl *comp)
329329{
330330 if (Strutil::starts_with (name, " ___" )) {
331331 comp->error (comp->filename (), comp->lineno (),
332332 " '%s' : sorry, can't start with three underscores" ,
333333 name);
334+ return false ;
335+ } else if (name == " this" ) {
336+ comp->error (comp->filename (), comp->lineno (),
337+ " 'this' not allowed in this context" );
338+ return false ;
334339 }
340+ return true ;
335341}
336342
337343
@@ -597,6 +603,9 @@ ASTvariable_declaration::ASTvariable_declaration (OSLCompilerImpl *comp,
597603 m_isparam(isparam), m_isoutput(isoutput), m_ismetadata(ismeta),
598604 m_initlist(initlist)
599605{
606+ if (! check_reserved ())
607+ return ;
608+
600609 if (m_initlist && init) {
601610 // Typecheck the init list early.
602611 ASSERT (init->nodetype () == compound_initializer_node);
@@ -606,8 +615,6 @@ ASTvariable_declaration::ASTvariable_declaration (OSLCompilerImpl *comp,
606615 m_typespec = type;
607616 if (! m_ismetadata)
608617 validate (warn_function_clash);
609- else
610- check_reserved ();
611618
612619 SymType symtype = isparam ? (isoutput ? SymTypeOutputParam : SymTypeParam)
613620 : SymTypeLocal;
0 commit comments