Students from the rest of the European Union who come to Scotland for their university education could be liable for fees after independence, new legal advice has suggested.

Universities Scotland commissioned advice on the issue in the wake of concerns that students from the rest of the UK may no longer have to pay tuition fees of up to £9,000 a year following independence.

Alastair Sim, the director of the sector body, said the legal advice showed it "may be possible to rely upon a residency requirement for preferential access to free higher education".

At the moment an SNP flagship policy means students from Scotland who go to university north of the border do not pay any tuition fees.

While students from the rest of the UK pay tuition fees, these do not apply to students from other countries in the European Union.

But concerns have been expressed that if Scotland were to become independent, students from the rest of the UK would have to be treated in the same way as EU students - meaning they would no longer have to pay fees.

Some fear that situation could lead to more people from the rest of the UK coming north of the border to study, with Scottish students potentially being squeezed out.

Professor David Bell from Stirling University told BBC Scotland that the Scottish Government "would not be able to charge students from England the same amount" if the country left the UK.

"They would have to charge them the same as Scottish students get charged, which is nothing," he said.

"A student from Newcastle instead of having to pay £9,000 a year could attend a Scottish institution for no fees at all."

He warned: "That will increase demand for places in Scotland, the possibility is that Scottish students might get squeezed out."

But Mr Sim said it may be possible to charge fees for students not normally resident in Scotland.

He told BBC Radio Scotland's Good Morning Scotland programme: "We commissioned this advice and it is coming back and saying it may be possible to rely upon a residency requirement for preferential access to free higher education.

"That provides a nucleus of a way forward that could be developed for thinking about how we can keep opportunities open for Scottish students while managing sustainable cross border flows."

He added: "EU citizens, including those resident in what would become the remnant of the UK in the event of Scottish independence, for all these EU residents who are not normally resident in Scotland it maybe possible to construct a rationale that enables them to be charged a fee, while maintaining free higher education for EU citizens who are normally resident in Scotland.

"At the moment EU citizens who are resident outside the UK are entitled to free higher education in Scotland.

"Developing from this advice it is possible also to look at whether this provides a basis for some form of contribution for students who are from the rest of the EU but not normally resident in Scotland, in the event of Scottish independence."

Mr Sim urged ministers to consider such a measure, stating: "There would certainly have to be an objective case built for why it is necessary to take this measure, but I think it's certainly giving the Scottish Government the nucleus of something to work on in the event of independence."

Tory education spokeswoman Liz Smith challenged the Scottish Government to set out who would have to pay university fees if Scotland was independent.

Ms Smith said: "Universities Scotland has published legal advice which makes it clear that charging fees to students in the rest of the UK would not, in fact, contravene EU law and that the current discriminatory fee structure could be maintained in an independent Scotland.

"Clearly, this has major implications for student applications and for university funding.

"The SNP needs to come clean and state unequivocally who would be charged fees in an independent Scotland, how this impacts on the Scottish Government's commitment to maintain free student access to higher education and the resulting costs to the public purse."

But Liberal Democrat education spokesman Liam McArthur said that for the last six years, "despite repeated promises, the Scottish Government has failed to find a way of legally charging students from the rest of the EU who attend Scottish universities".

He said: "The suggestion that there is now a get-out-of-jail-free card in relation to rUK (the rest of the UK) students attending Scottish universities in the event of independence lacks credibility.

"It is far more likely that if Scotland votes to leave the UK, rUK students would have the same status as EU students and Scottish universities would be left with a £220 million funding black hole."

A Scottish Government spokesman said: "Universities Scotland's legal advice is an interesting contribution to the debate.

"We are confident that we can maintain free education for Scots residents and maintain the balance of students from within and out-with Scotland post-independence. Scotland can and will maintain its distinctive approach.

"We will set out our own plans for higher education in due course."