diff --git a/src/ast/ast_infer_type.cpp b/src/ast/ast_infer_type.cpp index 108e6d2aa..159245e16 100644 --- a/src/ast/ast_infer_type.cpp +++ b/src/ast/ast_infer_type.cpp @@ -1927,6 +1927,17 @@ namespace das { if ( decl.type && decl.type->isExprType() ) { return; } + if ( !st->parent && decl.classMethod && decl.type && decl.type->baseType==Type::autoinfer ) { + // if its field:auto = cast(@@fun) - we demote to @@fun; this is only possible when its sealed in the base class + if ( decl.init && decl.init->rtti_isCast() ) { + auto castExpr = static_pointer_cast(decl.init); + if ( castExpr->castType && castExpr->castType->baseType==Type::autoinfer ) { + decl.init = castExpr->subexpr; + reportAstChanged(); + return; + } + } + } if ( decl.parentType ) { auto pf = st->parent->findField(decl.name); if ( !pf->type->isAutoOrAlias() ) { diff --git a/src/parser/parser_impl.cpp b/src/parser/parser_impl.cpp index a0890a174..4252d5c56 100644 --- a/src/parser/parser_impl.cpp +++ b/src/parser/parser_impl.cpp @@ -658,7 +658,7 @@ namespace das { auto vars = new vector(); vars->emplace_back(VariableNameAndPosition{varName,"",func->at}); Expression * finit = new ExprAddr(func->at, inThisModule(func->name)); - if ( ovr == OVERRIDE_OVERRIDE ) { + if ( ovr == OVERRIDE_OVERRIDE || ovr == OVERRIDE_SEALED ) { finit = new ExprCast(func->at, finit, make_smart(Type::autoinfer)); } VariableDeclaration * decl = new VariableDeclaration(