{"record":{"id":"cf54e84e1347db08","repo":"dotnet/runtime","slug":"s-d-error-s-at-token-s-in-s","errorCode":null,"errorMessage":"%s(%d) : error : %s at token '%s' in: %s\n","messagePattern":"(.+?)\\((.+?)\\) : error : (.+?) at token '(.+?)' in: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/coreclr/ilasm/grammar_after.cpp","lineNumber":245,"sourceCode":"        len &= ~(size_t)1;\n    }\n    memcpy(tokBuff, PENV->curTok, len);\n    tokBuff[len] = 0;\n    tokBuff[len+1] = 0;\n    if(PENV->bExternSource)\n    {\n        szfile = PASM->m_szSourceFileName;\n        iline = PENV->nExtLine;\n    }\n\n    const char* fmt = \"%s(%d) : error : %s at token '%s' in: %s\\n\";\n    if(Sym == SymW) // Unicode file\n    {\n        // CodeQL [SM02986] Casting tokBuff to WCHAR* is safe because tokBuff is WCHAR-aligned and properly null terminated\n        MAKE_UTF8PTR_FROMWIDE(tokBuffUtf8, (WCHAR*)tokBuff);\n        // CodeQL [SM02986] Casting yygetline result to WCHAR* is safe because buff is guaranteed to be WCHAR-aligned\n        MAKE_UTF8PTR_FROMWIDE(curLineUtf8, (WCHAR*)yygetline(PENV->curLine));\n        fprintf(stderr, fmt,\n                szfile, iline, str, tokBuffUtf8, curLineUtf8);\n    }\n    else\n    {\n        fprintf(stderr, fmt,\n                szfile, iline, str, tokBuff, yygetline(PENV->curLine));\n    }\n    parser->success = false;\n}\n\n/********************************************************************************/\n/* looks up the typedef 'name' of length 'nameLen' (name does not need to be\n   null terminated)   Returns 0 on failure */\nTypeDefDescr* findTypedef(_In_reads_(NameLen) char* name, size_t NameLen)\n{\n    TypeDefDescr* pRet = NULL;\n    static char Name[4096];\n    if(PASM->NumTypeDefs())","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/coreclr/ilasm/grammar_after.cpp#L227-L263","documentation":"This is the Unicode-file branch of ilasm's generic IL parse-error reporter (grammar_after.cpp:244-246). When the parser encounters an unexpected token in a UTF-16 source file, it formats `file(line) : error : <msg> at token '<tok>' in: <source line>` to stderr using MAKE_UTF8PTR_FROMWIDE conversions of the token and current line. The actual cause is identified by the `str` argument (the grammar-specific error text), with this printf being only the carrier.","triggerScenarios":"Any IL syntax error while assembling a Unicode (.il) source file: a malformed instruction, an undeclared symbol, a bad signature, a misplaced keyword.","commonSituations":"Hand-written or generated IL with a typo; copy-paste between files that changed an encoding; a code generator emitting IL the current ilasm grammar rejects.","solutions":["Read the `<msg>` (the `%s` error text) and the highlighted source line to find the exact grammar violation.","Open the .il file at the reported line and fix the offending token.","If unsure, re-disassemble a known-good DLL with ildasm and diff the IL.","Save the file as plain ANSI/UTF-8 if Unicode handling is the suspect."],"exampleFix":"// before (Unicode .il, line 12): .method void Foo(bar)\n// after:                                .method void Foo(bar) { ret }","handlingStrategy":"validation","validationCode":"// In a code generator, validate IL tokens before writing .il files.\n// Reject unknown opcodes / undeclared symbols so ilasm never sees them.\nif (!isKnownOpcode(tok) || !symbols.contains(operand)) {\n    fail('IL syntax error would occur at line ' + lineNo);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Round-trip test generated IL through ildasm->ilasm in CI.","Keep a golden set of valid IL snippets to diff against.","Pin the ilasm version that matches your IL grammar."],"tags":["ilasm","parser","syntax","unicode","il-source"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}