An optical sensor for measuring the distance to an object surface, which sensor comprises - an illumination system that is provided with a radiation source for supplying a measuring beam (b); - a focussing unit for focusing the measuring beam (b) to a spot on the object surface; - a detection system (42. 44, 46, 48, 52, 56, 58) comprising - a radiation-sensitive detector (56, 58) for measuring beam radiation reflected from the object surface into an electrical signal that represents the actually measured distance; and - a signal processing circuit (66, 68, 70) for processing this signal, characterized in that the optical sensor includes a pupil-sensing system for determining tilt of the object surface from the pupil radiation distribution, which pupil-sensing system comprises - a beam splitter, arranged between the focussing unit and the detector (56, 58), for splitting a reflected measuring beam (b') into a pupil-sensing beam (b 3 ') and a distance measuring beam, - a position-sensitive detector, arranged in the path of the pupil-sensing beam (b 3 ') such that the pupil-sensing beam incident on the position-sensitive detector is a collimated beam, the position-sensitive detector being configured to convert the pupil-radiation-distribution into electrical signals that represent tilt of the object surface; and - a tilt-error determining circuit (74, 76), which circuit (74, 76) comprises a look-up table obtained from calibration and is coupled to the signal processing circuit (74, 76) to correct the actually measured distance for tilt of the object surface area being measured. - an illumination system that is provided with a radiation source for supplying a measuring beam (b); - a focussing unit for focusing the measuring beam (b) to a spot on the object surface; - a detection system (42. 44, 46, 48, 52, 56, 58) comprising - a radiation-sensitive detector (56, 58) for measuring beam radiation reflected from the object surface into an electrical signal that represents the actually measured distance; and - a signal processing circuit (66, 68, 70) for processing this signal, characterized in that the optical sensor includes a pupil-sensing system for determining tilt of the object surface from the pupil radiation distribution, which pupil-sensing system comprises - a radiation-sensitive detector (56, 58) for measuring beam radiation reflected from the object surface into an electrical signal that represents the actually measured distance; and - a signal processing circuit (66, 68, 70) for processing this signal, characterized in that the optical sensor includes a pupil-sensing system for determining tilt of the object surface from the pupil radiation distribution, which pupil-sensing system comprises - a beam splitter, arranged between the focussing unit and the detector (56, 58), for splitting a reflected measuring beam (b') into a pupil-sensing beam (b 3 ') and a distance measuring beam, - a position-sensitive detector, arranged in the path of the pupil-sensing beam (b 3 ') such that the pupil-sensing beam incident on the position-sensitive detector is a collimated beam, the position-sensitive detector being configured to convert the pupil-radiation-distribution into electrical signals that represent tilt of the object surface; and - a tilt-error determining circuit (74, 76), which circuit (74, 76) comprises a look-up table obtained from calibration and is coupled to the signal processing circuit (74, 76) to correct the actually measured distance for tilt of the object surface area being measured.