fix Issue 9806 - assertion failure in struct.c:668

- Save Scope object to resolve forward references
- Do constant folding in template value argument comparison

Additional:
Add assertions to check AST identity in `ClassDeclaration::semantic` and `InterfaceDeclaration::semantic`.