The UK should be able to unilaterally cancel its withdrawal from the EU, according to a top European law officer.