diff --git a/src/compiler/parser-decl-symb-init.bas b/src/compiler/parser-decl-symb-init.bas index 8a86c8748..8a5f7b9ac 100644 --- a/src/compiler/parser-decl-symb-init.bas +++ b/src/compiler/parser-decl-symb-init.bas @@ -633,6 +633,7 @@ function cInitializer _ '' [x] top level -> allow up-casting '' [x] nested UDT initialization -> do not allow up-casting '' [ ] array element initialization -> allow up-casting + '' [x] NEW() -> allow up-casting '' No override in options? if( (options and FB_INIOPT_NOUPCAST) = 0 ) then @@ -641,8 +642,10 @@ function cInitializer _ if( ctx.last_ctx = NULL ) then ctx.options and= not FB_INIOPT_NOUPCAST - '' anything else, assume no upcasting - else + '' up-casting not explicitly enabled? + elseif( (options and FB_INIOPT_UPCAST) = 0 ) then + + '' then anything else, assume no up-casting ctx.options or= FB_INIOPT_NOUPCAST end if diff --git a/src/compiler/parser-quirk-mem.bas b/src/compiler/parser-quirk-mem.bas index 03c584387..0021348c1 100644 --- a/src/compiler/parser-quirk-mem.bas +++ b/src/compiler/parser-quirk-mem.bas @@ -190,7 +190,7 @@ function cOperatorNew( ) as ASTNODE ptr lexSkipToken( ) end if else - initexpr = cInitializer( tmp, FB_INIOPT_ISINI or FB_INIOPT_NOUPCAST, dtype, subtype ) + initexpr = cInitializer( tmp, FB_INIOPT_ISINI or FB_INIOPT_UPCAST, dtype, subtype ) if( initexpr = NULL ) then errReport( FB_ERRMSG_EXPECTEDEXPRESSION ) end if diff --git a/src/compiler/parser.bi b/src/compiler/parser.bi index 2937fbe39..d38aa4406 100644 --- a/src/compiler/parser.bi +++ b/src/compiler/parser.bi @@ -227,6 +227,7 @@ enum FB_INIOPT FB_INIOPT_ISINI = &h00000001 '' initializer (not an expression) FB_INIOPT_ISOBJ = &h00000002 '' object with constructor FB_INIOPT_NOUPCAST = &h00000004 '' don't allow upcasting (base types initialized from derived types) + FB_INIOPT_UPCAST = &h00000008 '' allow upcasting (as used by NEW() to reset the recursion checks) end enum '' cProcHeader() flags