Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!orion.oac.uci.edu!ucivax!milne From: milne@ics.uci.edu (Alastair Milne) Newsgroups: comp.lang.pascal Subject: Re: TP Scope violation bug Message-ID: <2813B60D.26899@ics.uci.edu> Date: 23 Apr 91 04:20:29 GMT References: <7232@oasys.dt.navy.mil> Distribution: usa Organization: UC Irvine Department of ICS Lines: 33 In <7232@oasys.dt.navy.mil> roth@oasys.dt.navy.mil (Pete Roth) writes: >{ > The enclosed program shows that Turbo Pascal 6.0 violates >the scope rules of Pascal by allowing the compilation and incorrect >execution of the program. Giving wrong answers, of course. > It looks to me like the table of function identifiers is not >searched when variable identifiers are "compiled." >} >PROGRAM aBug ; >(* demonstrates the violation of scope rules *) >FUNCTION x : LONGINT ; > VAR x : REAL ; ^^^^^^^^^^^^^ This is a more local occurrence than the function's name, which belongs to the enclosing scope. > BEGIN > x := Trunc( 1.0 ) This assigns to the most local version of 'x', which is of course the local variable. > END ; >BEGIN > WriteLn( 'output: ', x ) >END. This works exactly as I would expect: the variable x gets the assignment, the function remains unassigned, and the writeln reports an uninitialised value. No bug that I can see. Alastair Milne