Skip to content

Commit

Permalink
diagnostic of unresolved base class type
Browse files Browse the repository at this point in the history
- compiler does not crash and reports fatal error
  • Loading branch information
jakubmisek committed Mar 28, 2017
1 parent 602ec64 commit 04b871d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
29 changes: 21 additions & 8 deletions src/Peachpie.CodeAnalysis/Compilation/SourceCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ private void DiagnoseRoutine(SourceRoutineSymbol routine)
}
}

private void DiagnoseTypes()
{
this.WalkTypes(DiagnoseType);
}

private void DiagnoseType(SourceTypeSymbol type)
{
// resolves base types in here
var btype = type.BaseType;

// ...
}

internal void EmitMethodBodies()
{
Debug.Assert(_moduleBuilder != null);
Expand Down Expand Up @@ -247,19 +260,19 @@ public static IEnumerable<Diagnostic> BindAndAnalyze(PhpCompilation compilation)
var diagnostics = new DiagnosticBag();
var compiler = new SourceCompiler(compilation, null, true, diagnostics, CancellationToken.None);

// 1.Bind Syntax & Symbols to Operations (CFG)
// a.equivalent to building CFG
// b.most generic types(and empty type - mask)
// 1. Bind Syntax & Symbols to Operations (CFG)
// a. construct CFG, bind AST to Operation
// b. declare table of local variables
compiler.WalkMethods(compiler.EnqueueRoutine);
compiler.WalkTypes(compiler.EnqueueFieldsInitializer);

// 2.Analyze Operations
// a.declared variables
// b.build global variables/constants table
// c.type analysis(converge type - mask), resolve symbols
// d.lower semantics, update bound tree, repeat
// 2. Analyze Operations
// a. type analysis (converge type - mask), resolve symbols
// b. lower semantics, update bound tree, repeat
// c. collect diagnostics
compiler.AnalyzeMethods();
compiler.DiagnoseMethods();
compiler.DiagnoseTypes();

//
return diagnostics.AsEnumerable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public static IEnumerable<MethodSymbol> CreateCtors(SourceTypeSymbol type)

// resolve base .ctor that has to be called
var btype = type.BaseType;
Debug.Assert(!(btype is ErrorTypeSymbol));
var fieldsonlyctor = (MethodSymbol)(btype as IPhpTypeSymbol)?.InstanceConstructorFieldsOnly; // base..ctor() to be called if provided
var basectors = (fieldsonlyctor != null)
? ImmutableArray.Create(fieldsonlyctor)
Expand All @@ -160,8 +159,9 @@ public static IEnumerable<MethodSymbol> CreateCtors(SourceTypeSymbol type)
var basector = ResolveBaseCtor(givenparams, basectors);
if (basector == null)
{
throw new NotImplementedException("Base constructor cannot be resolved. Base class either does not exist or constructor parameters do not match.");
// type.BaseType was not resolved, reported by type.BaseType
// TODO: Err & ErrorMethodSymbol
yield break;
}

// create .ctor(s)
Expand Down

0 comments on commit 04b871d

Please sign in to comment.