Identify bugs in a given piece of code and fix them.
Asked in the Technical Interview stage. Code review exercise.
You are given a Python function that is intended to return the first duplicate value in a list of integers, or -1 if no duplicate exists. The current implementation contains bugs.
Write a corrected version of the function with the same signature:
def first_duplicate(nums):
The function must return the first value that appears more than once when scanning from left to right. If no value repeats, return -1.
def first_duplicate(nums):