Tier 0 · Story 01Complete
The Tyhp compiler uses a structured diagnostic system to report errors, warnings, and informational messages during compilation. Every diagnostic has a unique code, a severity level, and a human-readable message that includes the source file location. This page explains how to read and interpret compiler diagnostics.
Each diagnostic message follows a consistent format that includes the file path, line and column numbers, severity, diagnostic code, and a descriptive message:
filename(line,column): severity TYHPXXXX: message
For example, a type mismatch error would appear as:
src/Models/User.tyhp(42,5): error TYHP4008: Cannot assign type 'string' to type 'int'
The components are:
src/Models/User.tyhp -- the source file where the issue was detected(42,5) -- line 42, column 5 (1-indexed)error -- the severity level (error, warning, or info)TYHP4008 -- the unique diagnostic codeCannot assign type 'string' to type 'int' -- a human-readable description of the problemThe Tyhp compiler uses three severity levels for diagnostics:
ErrorA problem that prevents successful compilation. The build will fail and no PHP output will be produced. Errors must be fixed before the code can compile. Examples include type mismatches, missing return statements, and unresolved symbols.
WarningA potential issue that does not prevent compilation but may indicate a bug or questionable code. The build succeeds, but warnings should be investigated. When the --strict flag is used, warnings are treated as errors. Examples include unreachable code, possibly-null variables, and deprecated symbol usage.
InfoAn informational message or style suggestion. These do not affect compilation and are purely advisory. Examples include unnecessary null-safe operator usage and eval() detection.
Every diagnostic code follows the pattern TYHPXXXX where the first digit identifies the compiler phase that produced the diagnostic. This makes it easy to understand where in the compilation pipeline an issue was detected:
1000-1999: Parser/Lexer ErrorsErrors from the ANTLR4 parsing phase. These occur when the source code contains syntax that the parser cannot understand -- missing semicolons, unmatched braces, invalid token sequences, etc. Parser errors prevent AST construction for the affected file.
2000-2999: Visitor/AST ErrorsErrors from the parse tree to AST conversion phase. These occur when the parser produces a valid parse tree but the visitor encounters an unexpected grammar structure or unsupported language construct during AST construction.
3000-3999: Binder ErrorsErrors from the symbol resolution and scope management phase. These occur when the binder cannot resolve names, finds duplicate declarations, detects circular inheritance, or encounters invalid scope configurations.
4000-4999: Checker ErrorsErrors from the type checking and semantic analysis phase. This is the largest category and includes type mismatches, missing implementations, invalid modifier usage, accessibility violations, and all other semantic validation. Checker errors are the most common diagnostics encountered during development.
5000-5999: Emitter ErrorsErrors from the PHP code generation phase. These occur when the emitter cannot produce valid PHP output for a given AST construct, encounters output path conflicts, or fails to write files to disk.
6000-6999: Configuration ErrorsErrors related to project configuration. These occur when the tyhp.json configuration file contains invalid values, missing required fields, or references nonexistent paths.
7000-7999: CLI ErrorsErrors specific to the CLI build and lint actions. These include file-not-found errors for lint targets, output path conflicts during build, file write failures, and unsupported output format specifications.
8000-8999: Tyhpdef ErrorsErrors related to tyhpdef type definition files. These occur when tyhpdef files fail to parse, contain duplicate declarations, reference nonexistent paths, or encounter errors during tyhpdef generation.
9000-9999: Internal Compiler Errors (Reserved)Reserved for internal compiler errors that indicate bugs in the compiler itself. If you encounter an error in this range, please report it as a bug.
Here is an example of what a typical build output looks like when there are errors and warnings:
src/Models/User.tyhp(15,10): error TYHP3003: Symbol 'InvalidUser' not found
src/Models/User.tyhp(42,5): error TYHP4008: Cannot assign type 'string' to type 'int'
src/Services/Auth.tyhp(23,1): error TYHP4002: Multiple visibility modifiers specified
src/Services/Auth.tyhp(67,12): warning TYHP4012: Unreachable code detected
Build failed with 3 errors and 1 warning.
Files: 12 source files
Duration: 0.91s (parse: 0.45s, bind: 0.12s, check: 0.34s)
Errors: 3
Warnings: 1
Tier 1 · Story 14Complete
Beyond the basic file(line,column): severity CODE: message format, the Tyhp compiler renders diagnostics with rich, developer-focused detail. The renderer reuses the same diagnostic data carried by every phase, so text, JSON, and SARIF output stay consistent.
--quiet is set.help: hint in text output and as a machine-applicable fix in JSON and SARIF.tyhp lint --fix. Language server code actions are planned.--explain command — Run tyhp --explain TYHP4008 to print the long-form explanation for any diagnostic code. The error index is generated directly from the compiler's code registry, so it always matches the codes the compiler emits.Diagnostic messages follow a consistent style: present tense, the offending symbol or type named in backticks, and "expected X, found Y" framing. A build-time consistency gate enforces that every diagnostic code has conforming message text and vice versa.
tyhp --explain TYHP4008
Understanding the compilation pipeline helps in diagnosing errors. The Tyhp compiler processes your code through these sequential phases:
If errors occur in an earlier phase, the compiler may skip later phases. For example, if there are parser errors in a file, that file will not proceed through binding and checking. However, other files in the project continue to be processed, so you can see as many errors as possible in a single build.
Here are the most common categories of errors you will encounter and general strategies for resolving them:
Type Mismatch Errors (TYHP4008-4010)These are the most common checker errors. They occur when you try to assign, return, or pass a value of an incompatible type. Fix by ensuring the types align: add type casts where appropriate, change the declared type, or update the value. Check union types and nullable types carefully.
Unresolved Symbol Errors (TYHP3003)These occur when the compiler cannot find a class, function, constant, or variable you referenced. Common causes: missing use/import statement, typo in the name, the symbol is in a tyhpdef file that is not loaded, or the symbol is defined in a file that failed to parse.
Missing Implementation Errors (TYHP4017-4018)These occur when a concrete class does not implement all abstract methods from its parent class or all methods from its interfaces. Fix by implementing the missing methods with the correct signatures.
Variable Errors (TYHP4013-4016)These occur when variables are used before assignment, may be undefined on some code paths, or lack type information. Fix by initializing variables before use, adding null checks for conditional paths, or adding explicit type annotations.
Modifier Errors (TYHP4002-4007)These occur when visibility or member modifiers are used incorrectly. Examples: two visibility keywords on the same member, static on an interface method, or an accessor that is more visible than its property. Fix by correcting the modifier combinations.
tyhp lint instead of tyhp build when you only need to check for errors. Lint skips the emit and write phases, making it faster.tyhp lint --file src/MyClass.tyhp to check a single file while you are actively editing it.tyhp.json tyhpdef include paths.--strict flag treats warnings as errors. This is useful for CI pipelines but may be noisy during active development.output.phpVersion in tyhp.json.For CI/CD integration, the tyhp lint command supports JSON output via the --format json flag. Each diagnostic is serialized as a JSON object:
JSON range coordinates are 0-based lines (text diagnostics are 1-based). Column is 0-based in both. Line 42 in text output is "line": 41 here:
{
"severity": "error",
"code": "TYHP4008",
"file": "src/Models/User.tyhp",
"range": {
"start": { "line": 41, "column": 5 },
"end": { "line": 41, "column": 15 }
},
"message": "Cannot assign type 'string' to type 'int'"
}
This format is compatible with common CI reporting tools and IDE integrations.