Browse files

work on bugs

  • Loading branch information...
1 parent 2bb24fc commit 58400fd9a4789cb77725d1528bbfe8e5c24020ba @VladD2 VladD2 committed Mar 19, 2012
Showing with 30 additions and 15 deletions.
  1. +21 −13 Linq/Macro/ToExpressionImpl.n
  2. +2 −0 ncc/typing/TypedTree.n
  3. +7 −2 ncc/typing/Typer.n
View
34 Linq/Macro/ToExpressionImpl.n
@@ -52,13 +52,13 @@ namespace Nemerle.Linq
ToExpr(lparms : LParms, texpr : TExpr) : PExpr
{
+ def simplified = SimplefyTExpr(texpr);
def result =
- match (SimplefyTExpr(texpr))
+ match (simplified)
{
| MacroEnvelope(_, _, expended, _) => NestedToExpression(lparms, expended)
| DefFunctionsIn([header], _) => ConvertLambdaExpression(lparms, header)
- //| DebugInfo(expr, _) => ToExpr(lparms, expr)
- | Block(_, expr) => ToExpr(lparms, expr)
+ | Block(_, expr) => TryAddConvertion(lparms, simplified.Type, expr)
| LocalRef as r => ConvertLocalRefToClosuredField(lparms, r)
| PropertyMember(tObj, prop) => <[ Expression.Property($(ToExpr(lparms, tObj)), $(MakeMetodInfo(tObj.Type, prop))) ]>;
| Tuple(args) => ConvertTuple(lparms, args, texpr.Type)
@@ -81,6 +81,17 @@ namespace Nemerle.Linq
result
}
+ TryAddConvertion(lparms : LParms, requiredType : TypeVar, nestedExpr : TExpr) : PExpr
+ {
+ def result = ToExpr(lparms, nestedExpr);
+ def nestedType = nestedExpr.Type;
+
+ if (requiredType.Equals(_manager.InternalType.Object) && (!nestedType.CanBeNull || nestedType.IsValueType))
+ <[ Expression.Convert($result, typeof($(requiredType : typed))) ]>
+ else
+ result
+ }
+
NestedToExpression(lparms : LParms, tExpr : TExpr) : PExpr
{
def delay(val)
@@ -243,16 +254,13 @@ namespace Nemerle.Linq
def exprType = p.expr.Type;
def requiredType = p.required_type ?? exprType;
- if (exprType.TryRequire(requiredType) && !requiredType.Equals(_manager.InternalType.Object))
+ def needConvertion = requiredType.Equals(_manager.InternalType.Object) && (!exprType.CanBeNull || exprType.IsValueType);
+
+ if (exprType.TryRequire(requiredType) && !needConvertion)
result.Add(ToExpr(lparms, p.expr));
else
{
- // TODO> VLadD2: Implement literal type convertion
- //match (p.expr)
- //{
- // | TExpr.Literal(Literal.Integer as lit) => lit.AsSByte
- //}
-
+ // TODO: VLadD2: Implement literal type convertion
def exprTree = ToExpr(lparms, p.expr);
result.Add(<[ Expression.Convert($exprTree, typeof($(requiredType : typed))) ]>);
}
@@ -401,9 +409,9 @@ namespace Nemerle.Linq
//foreach (p in header.Parameters)
// p.decl.Register(); // To prevent assert in Typer2. After all, we transform the parameters into Expression tre.
- foreach (p when (p.Name == "keyXxx") in header.Parameters)
- {
- }
+ //foreach (p when (p.Name == "keyXxx") in header.Parameters)
+ //{
+ //}
def rType = header.ReturnType;
def rTypeRef = PExpr.TypedType(rType);
View
2 ncc/typing/TypedTree.n
@@ -877,7 +877,9 @@ namespace Nemerle.Compiler.Typedtree
mutable _ty : TypeVar;
public ty : TypeVar
{
+ [System.Diagnostics.DebuggerStepThrough]
get { _ty }
+ [System.Diagnostics.DebuggerStepThrough]
set { _ty = value }
}
View
9 ncc/typing/Typer.n
@@ -2895,9 +2895,14 @@ namespace Nemerle.Compiler
seen_empty_ctor = true;
def memTy = meth.GetMemType ();
def from = memTy.from;
- def mt = FixedType.Fun (from, memTy.argsCount, t.GetMemType ());
- def ty = t.FreshSubst ().Apply (mt);
+ def memType = t.GetMemType();
+ def mt = FixedType.Fun (from, memTy.argsCount, memType);
+ def ty = if (t.DeclaringType?.Equals(current_type))
+ mt
+ else
+ t.FreshSubst().Apply(mt);
def ret_type = (ty.FixedValue :> FixedType.Fun).to :> FixedType.Class;
+
when (add_constraint != null)
_ = Expect (add_constraint, ret_type, "constructor");
ConstrainLeadingTyparms (pt_from, ret_type);

0 comments on commit 58400fd

Please sign in to comment.