diff options
author | Martin Odersky <odersky@gmail.com> | 2013-07-23 11:42:45 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-07-23 11:42:45 +0200 |
commit | a2c0e29c9e2f8f06e9499c02ebd6e2c3666a0709 (patch) | |
tree | cfe65a300f8e0a777d5c75efedc8d04c6c230cfa /src/dotty/tools/dotc/typer/ErrorReporting.scala | |
parent | 9169d5ee101ef7d4f6b797e64e06e4e5df2de7e9 (diff) | |
download | dotty-a2c0e29c9e2f8f06e9499c02ebd6e2c3666a0709.tar.gz dotty-a2c0e29c9e2f8f06e9499c02ebd6e2c3666a0709.tar.bz2 dotty-a2c0e29c9e2f8f06e9499c02ebd6e2c3666a0709.zip |
Some refactorings and additions on error reporting.
Also, removed redundant Trees. prefixes in patterns.
Diffstat (limited to 'src/dotty/tools/dotc/typer/ErrorReporting.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/ErrorReporting.scala | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/typer/ErrorReporting.scala b/src/dotty/tools/dotc/typer/ErrorReporting.scala new file mode 100644 index 000000000..ef6184394 --- /dev/null +++ b/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -0,0 +1,66 @@ +package dotty.tools +package dotc +package typer + +import ast._ +import core._ +import Trees._ +import Types._, Contexts._, Decorators._, Denotations._ +import Applications._ +import util.Positions._ + +object ErrorReporting { + + import tpd._ + + def errorTree(tree: Trees.Tree[_], msg: => String)(implicit ctx: Context): tpd.Tree = { + ctx.error(msg, tree.pos) + tree withType ErrorType + } + + class Errors(implicit ctx: Context) { + + def expectedTypeStr(tp: Type): String = tp match { + case tp: FunProtoType => + val result = tp.resultType match { + case tp: WildcardType => "" + case tp => s"and expected result type $tp" + } + s"arguments (${tp.typedArgs map (_.tpe.show) mkString ", "})$result" + case _ => + s"expected type ${tp.show}" + } + + def anonymousTypeMemberStr(tpe: Type) = { + val kind = tpe match { + case _: TypeBounds => "type with bounds" + case _: PolyType | _: MethodType => "method" + case _ => "value of type" + } + s"$kind $tpe" + } + + def overloadedAltsStr(alts: List[SingleDenotation]) = + s"overloaded alternatives of ${denotStr(alts.head)} with types\n" + + s" ${alts map (_.info) mkString "\n "}" + + def denotStr(denot: Denotation): String = + if (denot.isOverloaded) overloadedAltsStr(denot.alternatives) + else if (denot.symbol.exists) denot.symbol.showLocated + else anonymousTypeMemberStr(denot.info) + + def refStr(tp: Type): String = tp match { + case tp: NamedType => denotStr(tp.denot) + case _ => anonymousTypeMemberStr(tp) + } + + def typeMismatch(tree: Tree, pt: Type): Tree = + errorTree(tree, + s"""type mismatch: + | found : ${tree.tpe.show} + | required: ${pt.show}""".stripMargin) + + } + + def err(implicit ctx: Context): Errors = new Errors +}
\ No newline at end of file |